Fix memory leak for 'path' 15/310615/2 accepted/tizen_7.0_unified tizen_7.0 accepted/tizen/7.0/unified/20240503.164339
authorJiyong <jiyong.min@samsung.com>
Thu, 2 May 2024 03:32:08 +0000 (12:32 +0900)
committerJiyong <jiyong.min@samsung.com>
Fri, 3 May 2024 01:23:04 +0000 (10:23 +0900)
Change-Id: I086221beb8558d7bce5b0bc348e96e1a6b46f0c9

packaging/capi-media-controller.spec
src/media_controller_util.c

index 5ca01429142be7b3eb7c97228c75fcc99b56b122..b06f182d02d3154fdbf1741a05dc99e456d1b4d1 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-controller
 Summary:    A media controller library in Tizen Native API
-Version:    0.2.38
+Version:    0.2.39
 Release:    1
 Group:      Multimedia/API
 License:    Apache-2.0
index 476d69ccfc4358ac48bdc1cfeaee84e2ff685578..26f1c879616271a33e6aa36ecdc6086b34057067 100644 (file)
@@ -309,12 +309,11 @@ static gchar *_mc_util_make_message_file(void)
        int fd = 0;
        gchar *path = NULL;
        const char *template = "XXXXXX.mc";
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
 
        fd = g_file_open_tmp(template, &path, &error);
        if (fd < 0) {
                mc_secure_error("g_file_open_tmp error [%s]", (error ? error->message : "none"));
-               g_error_free(error);
                return NULL;
        }
 
@@ -327,24 +326,23 @@ static gchar *_mc_util_make_message_file(void)
 
 gchar *_mc_util_write_message_to_file(const gchar *data, gssize size)
 {
-       gchar *path = _mc_util_make_message_file();
-       GError *error = NULL;
+       g_autofree gchar *path = NULL;
+       g_autoptr(GError) error = NULL;
 
-       mc_retvm_if(!MC_STRING_VALID(path), NULL, "invalid path %s", path);
        mc_retvm_if(!data, NULL, "data is null");
        mc_retvm_if(size == 0, NULL, "size is 0");
 
        mc_debug_fenter();
 
+       path = _mc_util_make_message_file();
+       mc_retvm_if(!path, NULL, "Making message file was failed");
+
        if (!g_file_set_contents(path, data, size, &error)) {
                mc_secure_error("g_file_set_contents error(%s: %s)", path, (error ? error->message : "none"));
-               if (error)
-                       g_error_free(error);
-               g_free(path);
                return NULL;
        }
 
        mc_debug_fleave();
 
-       return path;
+       return g_steal_pointer(&path);
 }