Fix memory leak 88/244688/4 accepted/tizen_6.0_unified_hotfix tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.115617 accepted/tizen/6.0/unified/hotfix/20201103.004326 accepted/tizen/unified/20201005.005817 submit/tizen/20200924.064724 submit/tizen/20200925.070823 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 tizen_6.0.m2_release
authorYunmi Ha <yunmi.ha@samsung.com>
Wed, 23 Sep 2020 08:07:00 +0000 (17:07 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Wed, 23 Sep 2020 09:01:29 +0000 (18:01 +0900)
-After call g_variant_get function with string format,
should call free.

Change-Id: I6d2f74e4aaf920030ae3b691ea6705fb6f8623cf
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/storage-external-dbus.c
src/storage-inhouse.c

index 5d45189..731296a 100755 (executable)
@@ -395,6 +395,8 @@ int storage_ext_get_storage_level(const char *path, char **level)
 
        g_variant_get(result, "(s)", &tmp);
        *level = strdup(tmp);
+       g_free(tmp);
+
        if (*level == NULL)
                return -ENOMEM;
 
index 2ec6f08..b35c4fb 100755 (executable)
@@ -164,7 +164,9 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig
 API int storage_get_primary_sdcard(int *storage_id, char **path)
 {
        GVariant *result;
-       storage_ext_device info;
+       int ret;
+       char *mount_point = NULL;
+       int id;
 
        if (!storage_id || !path)
                return STORAGE_ERROR_INVALID_PARAMETER;
@@ -185,25 +187,33 @@ API int storage_get_primary_sdcard(int *storage_id, char **path)
        }
 
        g_variant_get(result, "(issssssisibii)",
-                       &info.type, &info.devnode, &info.syspath,
-                       &info.fs_usage, &info.fs_type,
-                       &info.fs_version, &info.fs_uuid,
-                       &info.readonly, &info.mount_point,
-                       &info.state, &info.primary,
-                       &info.flags, &info.storage_id);
+                       NULL, NULL, NULL,
+                       NULL, NULL,
+                       NULL, NULL,
+                       NULL, &mount_point,
+                       NULL, NULL,
+                       NULL, &id);
 
        g_variant_unref(result);
 
-       if (info.storage_id < 0)
-               return STORAGE_ERROR_NO_DEVICE;
+       if (id < 0) {
+               ret = STORAGE_ERROR_NO_DEVICE;
+               goto out;
+       }
 
-       *path = strdup(info.mount_point);
-       if (*path == NULL)
-               return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error
+       *path = strdup(mount_point);
+       if (*path == NULL) {
+               ret = STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error
+               goto out;
+       }
 
-       *storage_id = info.storage_id;
+       *storage_id = id;
 
-       return STORAGE_ERROR_NONE;
+       ret = STORAGE_ERROR_NONE;
+out:
+       g_free(mount_point);
+
+       return ret;
 }
 
 API int storage_get_storage_level(const char *path, char **level)