mv_common: fix memory leak issue 01/279601/3 submit/tizen/20220812.070529 submit/tizen/20220817.123406
authorInki Dae <inki.dae@samsung.com>
Fri, 12 Aug 2022 06:45:49 +0000 (15:45 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 12 Aug 2022 06:56:14 +0000 (15:56 +0900)
[Version] : 0.23.15-0
[Issue type] : bug fix

Fixed memory leak issue of mv_engine_config_get_array_string_attribute_c
function.

Change-Id: Id490ddc88c8242c8ecb405230cdb4d934791b4f7
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_common/src/mv_common_c.cpp
packaging/capi-media-vision.spec

index 21071e4..76b249b 100644 (file)
@@ -657,13 +657,25 @@ int mv_engine_config_get_array_string_attribute_c(
                (*values)[idx] = (char*)malloc(sizeof(char) * (stringSize + 1));
                if ((*values)[idx] == NULL) {
                        LOGE("Failed to convert string to char*");
+
+                       for (int start = idx - 1; start >= 0; --start) {
+                               free((*values)[start]);
+                               ((*values)[start]) = NULL;
+                       }
+
+                       free(*values);
                        return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
                }
 
                if (attributeValue[idx].copy((*values)[idx], stringSize) != attributeValue[idx].size()) {
                        LOGE("Conversion from string to char* failed");
-                       free((*values)[idx]);
-                       ((*values)[idx]) = NULL;
+
+                       for (int start = idx; start >= 0; --start) {
+                               free((*values)[start]);
+                               ((*values)[start]) = NULL;
+                       }
+
+                       free(*values);
                        return MEDIA_VISION_ERROR_INVALID_OPERATION;
                }
                ((*values)[idx])[stringSize] = '\0';
@@ -672,23 +684,6 @@ int mv_engine_config_get_array_string_attribute_c(
                        name, idx, (*values)[idx]);
        }
 
-       /*
-       if ((*value) == NULL) {
-               LOGE("Failed to convert string to char*");
-               return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
-       }
-
-       if (attributeValue.copy(*value, stringSize) != attributeValue.size()) {
-               LOGE("Conversion from string to char* failed");
-               free(*value);
-               (*value) = NULL;
-               return MEDIA_VISION_ERROR_INVALID_OPERATION;
-       }
-       (*value)[stringSize] = '\0';
-
-       LOGD("Attribute [%s] (value %s) has been gotten",
-                       name, *value);
-       */
        return ret;
 }
 
index 7121aa7..41b16b2 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.23.14
+Version:     0.23.15
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause