Use g_malloc0/g_free instead of malloc/free 60/231460/4
authorYoungHun Kim <yh8004.kim@samsung.com>
Wed, 22 Apr 2020 05:25:53 +0000 (14:25 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Wed, 22 Apr 2020 07:58:10 +0000 (07:58 +0000)
Change-Id: Ibefc3b87ed4f5cfeb4e97cceb5e7c819420acf09

server/src/muse_server_config.c
server/src/muse_server_private.c
unittest/muse_gtest_json.cpp

index f9af605..60e0105 100644 (file)
@@ -126,11 +126,7 @@ static int _ms_config_parser(ms_config_t *conf)
                g_strstrip(host);
                conf->host[host_idx] = strdup(host);
                LOGD("host: %s", conf->host[host_idx]);
-               key = (char *)malloc(MUSE_MSG_LEN_MAX);
-               if (!key) {
-                       LOGE("Error - null key");
-                       goto out;
-               }
+               key = (char *)g_malloc0(MUSE_MSG_LEN_MAX);
 
                conf->host_infos[host_idx] = (host_info_t *) calloc(1, sizeof(host_info_t));
                if (!conf->host_infos[host_idx]) {
@@ -180,7 +176,7 @@ static int _ms_config_parser(ms_config_t *conf)
 
                host = strtok_r(NULL, INI_PARSER_COMMA, &ptr);
                conf->host_cnt++;
-               free(key);
+               g_free(key);
        }
 
        free(hosts);
index 2c91182..3226b02 100644 (file)
@@ -729,20 +729,11 @@ void ms_gst_init(char **cmd)
 
        gst_param_cnt = ms_config_get_gst_param_cnt();
 
-       argc = malloc(sizeof(gint));
-       muse_return_if_fail(argc);
+       argc = g_malloc0(sizeof(gint));
 
        /* add gst_param */
-       argv = malloc(sizeof(gchar *) * (gst_param_cnt + 1));
-       if (!argv) {
-               LOGE("argv memory leak allocation failed");
-               free(argc);
-               return;
-       }
-
-       memset(argv, 0, sizeof(gchar *) * (gst_param_cnt + 1));
+       argv = g_malloc0(sizeof(gchar *) * (gst_param_cnt + 1));
 
-       *argc = 0;
        argv[*argc] = (gchar *)cmd[0];
        (*argc)++;
        for (; (*argc) <= gst_param_cnt; (*argc)++)
@@ -759,8 +750,8 @@ void ms_gst_init(char **cmd)
        LOGI("gst_init_check is completed");
 
        /* release */
-       free(argv);
-       free(argc);
+       g_free(argv);
+       g_free(argc);
 
        LOGI("complete to initialize gstreamer");
 
index 4e5b33b..0614d43 100644 (file)
@@ -48,11 +48,7 @@ static gint _read_file(gchar *file_path, gchar **buf)
        file_size = ftell(fp);
        fseek(fp, 0, SEEK_SET);
 
-       tbuf = (gchar*)g_malloc0(file_size);
-       if (!tbuf) {
-               LOGE("Memory allocation failed");
-               goto error;
-       }
+       tbuf = (gchar *)g_malloc0(file_size);
 
        if (!fgets(tbuf, file_size, fp)) {
                LOGE("Read error");