heart-memory: Free array before exiting the function 37/315737/1
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 4 Dec 2024 02:23:01 +0000 (11:23 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 4 Dec 2024 04:26:25 +0000 (13:26 +0900)
Free array before exiting the function call when it is failed by error.

Change-Id: Ib825451c7f63785d8b7f34602e54727b386288ce
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-monitor/heart-memory.c

index 3aca2c17dba4379ea9527421072c51d26bd572d6..4921baa5057cd3dee830838bf0b19f0d7764dd57 100644 (file)
@@ -927,6 +927,7 @@ void heart_memory_update(struct logging_table_form *data, void *user_data)
 
                ret = pthread_mutex_lock(&heart_memory_mutex);
                if (ret) {
+                       g_array_free(table->memory_info, TRUE);
                        free(table);
                        _E("pthread_mutex_lock() failed, %d", ret);
                        return;
@@ -1131,7 +1132,7 @@ static void dbus_get_memory_data_list(GDBusMethodInvocation *invocation, GVarian
 {
        int i, ret, period = -1;
        char *appid, *pkgid;
-       GArray *temp_array;
+       GArray *temp_array = NULL;
        GVariantBuilder builder, *sub_builder;
 
        do_expr_unless_g_variant_get_typechecked(goto failure, params, "(i)", &period);
@@ -1171,6 +1172,9 @@ static void dbus_get_memory_data_list(GDBusMethodInvocation *invocation, GVarian
        return;
 
 failure:
+       if (temp_array)
+               g_array_free(temp_array, true);
+
        D_BUS_REPLY_ERR(invocation);
 }