Fix memory leak for 'path' 64/310564/4
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 00:58:47 +0000 (09:58 +0900)
Change-Id: I086221beb8558d7bce5b0bc348e96e1a6b46f0c9

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

index 2042170c67c2234b184df8796dcc867fff770748..f944c5574cdb89dd43f03b22303ac28460d8e0a8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-controller
 Summary:    A media controller library in Tizen Native API
-Version:    1.0.0
+Version:    1.0.1
 Release:    1
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -76,7 +76,7 @@ export LDFLAGS+=" -lgcov"
 %endif
 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-SO_FULLVER=0.3.0
+SO_FULLVER=0.3.1
 SO_MAJORVER=`echo ${SO_FULLVER} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DSO_FULLVER=${SO_FULLVER} -DSO_MAJORVER=${SO_MAJORVER} \
 %if %{on_demand}
index f3cd2f7b2f15887c7fd0739fca3d053ebf57a26d..defa9495e2ec95e9b28377efbce64c2196c1c277 100644 (file)
@@ -305,12 +305,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;
        }
 
@@ -323,24 +322,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);
 }