Fix Coverity issues 29/263429/3 accepted/tizen/unified/20210903.142943 submit/tizen/20210903.050853
authorGilbok Lee <gilbok.lee@samsung.com>
Thu, 2 Sep 2021 06:39:09 +0000 (15:39 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Fri, 3 Sep 2021 03:20:02 +0000 (12:20 +0900)
Change-Id: I3f057e1fe00c6187ea6e041a1a34c8d022c2b7b9

packaging/esplusplayer.spec
src/esplusplayer/src/esplayer.cpp
src/esplusplayer/src/esplusplayer_capi.cpp
src/plusplayer-core/src/gst_utils.cpp
ut/include/esplusplayer/esreader.hpp
ut/src/esplusplayer/ut_basic.cpp
ut/src/esplusplayer/ut_display.cpp
ut/src/plusplayer/utility.cpp
ut/src/ut_main.cpp

index 07eb39c..98256d1 100644 (file)
@@ -2,7 +2,7 @@
 %bcond_without ESPLUSPLAYER_UT
 Name:       esplusplayer
 Summary:    new multimedia streaming player
-Version:    0.0.1
+Version:    0.0.2
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 58025d1..794265a 100644 (file)
@@ -41,7 +41,7 @@ namespace util {
 
 std::uint64_t ConvertMsToNs(std::uint64_t ms) {
   constexpr std::uint64_t ns_unit = 1000000;
-  if (ms * ns_unit > G_MAXUINT64) return G_MAXUINT64;
+  if (ms > (G_MAXUINT64 / ns_unit)) return G_MAXUINT64;
   return ms * ns_unit;
 }
 std::uint64_t ConvertNsToMs(std::uint64_t ns) {
@@ -51,7 +51,7 @@ std::uint64_t ConvertNsToMs(std::uint64_t ns) {
 
 std::int64_t ConvertMsToNs(std::int64_t ms) {
   constexpr std::int64_t ns_unit = 1000000;
-  if (ms * ns_unit > G_MAXINT64) return G_MAXINT64;
+  if (ms > (G_MAXINT64 / ns_unit)) return G_MAXINT64;
   return ms * ns_unit;
 }
 std::int64_t ConvertNsToMs(std::int64_t ns) {
@@ -221,7 +221,11 @@ EsPlayer::EsPlayer() {
 
 EsPlayer::~EsPlayer() {
   LOG_ENTER_P(this);
-  Close();
+  try {
+    Close();
+  } catch (...) {
+    LOG_ERROR("Close failed");
+  }
   LOG_LEAVE_P(this);
 }
 
@@ -478,7 +482,12 @@ bool EsPlayer::Prepare_() {
       }
     }
     trackrenderer_->SetTrack(active_track);
-    SetTrackRendererAttributes_();
+    try {
+      SetTrackRendererAttributes_();
+    } catch (...) {
+      LOG_ERROR_P(this, "SetTrackRendererAttributes_ failed");
+      return false;
+    }
     if (!trackrenderer_->Prepare()) {
       return false;
     }
index 7b8aa6c..948f2fb 100644 (file)
@@ -266,13 +266,15 @@ class listener_bridge : public plusplayer::EsEventListener {
   virtual void OnMediaPacketVideoDecoded(
       const plusplayer::DecodedVideoPacket& packet) {
     if (this->media_packet_video_decoded_cb_ == nullptr) return;
+    if (!decoded_pkt_mgr_) return;
 
     auto* _pkt = new esplusplayer_decoded_video_packet();
     _pkt->pts = packet.pts;
     _pkt->duration = packet.duration;
     _pkt->surface_data = static_cast<void*>(packet.surface_data);
     _pkt->private_data = packet.buffer_addr;
-    if (decoded_pkt_mgr_ && decoded_pkt_mgr_->TryToAdd(_pkt)) {
+
+    if (decoded_pkt_mgr_->TryToAdd(_pkt)) {
       this->media_packet_video_decoded_cb_(
           _pkt, media_packet_video_decoded_cb_userdata_);
     } else {
index a6fb4c7..2036e8b 100644 (file)
@@ -238,6 +238,7 @@ GstElement* MakeCapsFilter(GstPad * pad, GstElementFactoryListType type, const c
 char** GetCookieList(const char* cookies) {
   char **cookie_list = nullptr;
   char *temp = nullptr;
+  char *trim = nullptr;
   guint i = 0;
 
   if (!cookies || !strlen(cookies))
@@ -245,13 +246,13 @@ char** GetCookieList(const char* cookies) {
 
   SECURE_LOG_DEBUG("cookies : %zu[bytes] - %s", strlen(cookies), cookies);
 
-  temp = g_strdup(cookies);
+  trim = temp = g_strdup(cookies);
 
   /* trimming. it works inplace */
-  g_strstrip(temp);
+  g_strstrip(trim);
 
   /* split */
-  cookie_list = g_strsplit(temp, ";", 100);
+  cookie_list = g_strsplit(trim, ";", 100);
 
   if (!cookie_list) {
     LOG_ERROR("failed to get cookie list");
index 4799f0d..3878f42 100644 (file)
@@ -53,32 +53,32 @@ class EsStreamReader {
 
   bool SetStreamInfo(esplusplayer_handle& esplayer) {
     if (type_ == ESPLUSPLAYER_STREAM_TYPE_AUDIO) {
-      esplusplayer_audio_stream_info audio_stream;
+      esplusplayer_audio_stream_info audio_stream = {};
       audio_stream.codec_data = nullptr;
       audio_stream.codec_data_length = 0;
       GetExtraData_(audio_stream.codec_data, audio_stream.codec_data_length);
       if (!GetMediaInfo_(audio_stream)) {
         if (audio_stream.codec_data != nullptr)
-          delete audio_stream.codec_data;
+          delete[] audio_stream.codec_data;
         return false;
       }
 
       esplusplayer_set_audio_stream_info(esplayer, &audio_stream);
       if (audio_stream.codec_data != nullptr)
-        delete audio_stream.codec_data;
+        delete[] audio_stream.codec_data;
     } else if (type_ == ESPLUSPLAYER_STREAM_TYPE_VIDEO) {
-      esplusplayer_video_stream_info video_stream;
+      esplusplayer_video_stream_info video_stream = {};
       video_stream.codec_data = nullptr;
       video_stream.codec_data_length = 0;
       GetExtraData_(video_stream.codec_data, video_stream.codec_data_length);
       if (!GetMediaInfo_(video_stream)) {
         if (video_stream.codec_data != nullptr)
-          delete video_stream.codec_data;
+          delete[] video_stream.codec_data;
         return false;
       }
       esplusplayer_set_video_stream_info(esplayer, &video_stream);
       if (video_stream.codec_data != nullptr)
-        delete video_stream.codec_data;
+        delete[] video_stream.codec_data;
     }
     return true;
   }
@@ -101,8 +101,8 @@ class EsStreamReader {
       int size = videobytestream2nalunit(tmp);
 
       if (size <= 0) {
+        delete[] tmp;
         return false;
-        delete tmp;
       }
 
       pkt.buffer = new char[size];
@@ -117,8 +117,8 @@ class EsStreamReader {
       int size = audiobytestream2nalunit(tmp);
 
       if (size <= 0) {
+        delete[] tmp;
         return false;
-        delete tmp;
       }
       pkt.buffer = new char[size];
 
@@ -130,7 +130,7 @@ class EsStreamReader {
 
       pts += ES_DEFAULT_VIDEO_PTS_OFFSET;
     }
-    delete tmp;
+    delete[] tmp;
     return true;
   }
 
index 769a800..3afc1d0 100644 (file)
@@ -42,8 +42,10 @@ class EsTest : public ::testing::Test {
 
 class EsBasicTest : public ::testing::TestWithParam<std::string> {
  public:
-  EsBasicTest() : util_(Utility::Instance()), esplayer_(nullptr) {
-    std::cout << "EsBasicTest()" << std::endl; }
+  EsBasicTest() : util_(Utility::Instance()), esplayer_(nullptr), callback_(nullptr),
+      uri_(), video_reader_(nullptr), audio_reader_(nullptr) {
+    std::cout << "EsBasicTest()" << std::endl;
+  }
   ~EsBasicTest() { std::cout << "~EsBasicTest()" << std::endl; }
 
   static void SetUpTestCase() {
@@ -132,8 +134,7 @@ TEST_F(EsTest, vdapi_basic_esplusplayer_get_error_string_p_1) {
   esplusplayer_handle esplayer = esplusplayer_create();
   ASSERT_NE(nullptr, esplayer);
   ASSERT_EQ(esplusplayer_open(esplayer), ESPLUSPLAYER_ERROR_TYPE_NONE);
-  const char* error = new char[100];
-  error =
+  std::string error =
       esplusplayer_get_error_string(ESPLUSPLAYER_ERROR_TYPE_NOT_SUPPORTED_FILE);
   std::cout << "error type" << error << std::endl;
   ASSERT_EQ(esplusplayer_close(esplayer), ESPLUSPLAYER_ERROR_TYPE_NONE);
index aac1d90..b80e213 100755 (executable)
@@ -44,8 +44,10 @@ namespace es_tc_diaplay {
 
 class EsDisplayTest : public ::testing::TestWithParam<std::string> {
  public:
-  EsDisplayTest(void) : util_(Utility::Instance()), esplayer_(nullptr) {
-    std::cout << "EsDisplayTest()" << std::endl; }
+  EsDisplayTest(void) : util_(Utility::Instance()), esplayer_(nullptr), callback_(nullptr),
+    uri_(), video_reader_(nullptr), audio_reader_(nullptr) {
+    std::cout << "EsDisplayTest()" << std::endl;
+  }
   ~EsDisplayTest() { std::cout << "~EsDisplayTest()" << std::endl; }
 
   static void SetUpTestCase() {
index 049f6ab..441cc5e 100644 (file)
@@ -115,7 +115,7 @@ bool Utility::PrepareESPP(esplusplayer_handle player, std::string& uri,
 void Utility::FeedingEsPacket(esplusplayer_handle player,
                               const esplusplayer_stream_type type,
                               const std::string& uri) {
-  EsStreamReader* reader;
+  EsStreamReader* reader = nullptr;
   auto feeding_task_fn = [this, &player, &reader]() {
     esplusplayer_es_packet pkt;
     while (true) {
@@ -134,6 +134,7 @@ void Utility::FeedingEsPacket(esplusplayer_handle player,
   }
   auto feeding_task = std::thread(feeding_task_fn);
   if (feeding_task.joinable()) feeding_task.join();
+  if (reader != nullptr) delete reader;
 }
 
 void Utility::DestroyESPP(esplusplayer_handle player) {
index 177f819..ec13bdf 100755 (executable)
@@ -5,14 +5,14 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
+  try {
+    ::testing::InitGoogleTest(&argc, argv);
+    ::testing::InitGoogleMock(&argc, argv);
+  } catch (...) {
+    return -1;
+  }
 
-  ::testing::InitGoogleTest(&argc, argv);
-  ::testing::InitGoogleMock(&argc, argv);
-
-  auto ret = -1;
-  ret = RUN_ALL_TESTS();
-
-
-  return ret;
+  return RUN_ALL_TESTS();
 }