[ML][common] Fix a Coverity issue 92/258492/1
authorPawel Wasowski <p.wasowski2@samsung.com>
Tue, 18 May 2021 14:11:12 +0000 (16:11 +0200)
committerPawel Wasowski <p.wasowski2@samsung.com>
Tue, 18 May 2021 14:11:12 +0000 (16:11 +0200)
Coverity issue numver: 1229783

This commit fixes a potential memory leak.

[Verification] The code compiles (it's hard to provoke the code to enter
the problematic branch, so the new code wasn't executed)

Change-Id: Id560ffdffc18ff6bbf2bc987e8e0ad6853b2cdb6

src/ml/ml_tensors_info_manager.cc

index 46623df..431b20d 100644 (file)
@@ -105,6 +105,10 @@ std::shared_ptr<TensorsInfo> TensorsInfo::CreateClone(int cloneId) {
   ret = ml_tensors_info_clone(clone_h, this->Handle());
   if (ML_ERROR_NONE != ret) {
     LoggerE("ml_tensors_info_clone failed: %d (%s)", ret, get_error_message(ret));
+    ret = ml_tensors_info_destroy(clone_h);
+    if (ML_ERROR_NONE != ret) {
+      LoggerE("ml_tensors_info_destroy failed: %d (%s)", ret, get_error_message(ret));
+    }
     return nullptr;
   }
   auto t = std::make_shared<TensorsInfo>(clone_h, cloneId);