heart-battery: Free memory before exiting the function 36/315736/1
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 4 Dec 2024 02:15:14 +0000 (11:15 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 4 Dec 2024 04:26:25 +0000 (13:26 +0900)
Free array and builder before exiting the function
when it is failed by error.

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

index a8b8c3651177a8d557a3eaff465310fb5c8c1922..9cf2c49a722ab9ea82e1da041a574405573ff5c9 100644 (file)
@@ -2754,8 +2754,8 @@ static void dbus_get_battery_capacity_history_latest(GDBusMethodInvocation *invo
        }
        if (heart_battery_get_capacity_history_latest(arrays, charge, max_size) != RESOURCED_ERROR_NONE) {
                _E("Failed to get capacity history latest");
-               D_BUS_REPLY_ERR(invocation);
-               return;
+               g_array_free(arrays, TRUE);
+               goto failure;
        }
 
        g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE);
@@ -2848,6 +2848,7 @@ static void dbus_get_battery_capacity_history(GDBusMethodInvocation *invocation,
        if (ret) {
                _E("pthread_mutex_unlock() failed, %d", ret);
                g_variant_builder_unref(sub_builder);
+               g_variant_builder_clear(&builder);
                goto failure;
        }