From 94ea47b6e6a9cae12acb6522549dcc46dbb80362 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 14 May 2020 10:40:22 +0900 Subject: [PATCH] Fix memory leak -The g_variant_builder_new() function's return value should be freed by g_variant_builder_unref() when it is no longer needeed -Release the memory allocated by g_malloc Change-Id: I56e45cef7b2ccadc700b3af71b40a33e670e36c3 Signed-off-by: Ilho Kim (cherry picked from commit 4f73703640b6d1622a2b2ed5985a5c5a3f86b80f) --- installer/pkgmgr_installer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/installer/pkgmgr_installer.c b/installer/pkgmgr_installer.c index cfbb99f..f62c444 100644 --- a/installer/pkgmgr_installer.c +++ b/installer/pkgmgr_installer.c @@ -184,6 +184,7 @@ static int __send_signal_for_event(pkgmgr_installer *pi, const char *pkg_type, char *sid; const char *tmp_appid = appid; const char *signal_name; + GVariant *v; GVariantBuilder *builder; GError *err = NULL; @@ -203,11 +204,13 @@ static int __send_signal_for_event(pkgmgr_installer *pi, const char *pkg_type, builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)")); g_variant_builder_add(builder, "(sss)", pkgid, (tmp_appid ? tmp_appid : ""), pkg_type); + v = g_variant_new("(usa(sss)ss)", + pi->target_uid, sid, builder, key, val); + g_variant_builder_unref(builder); if (g_dbus_connection_emit_signal(pi->conn, NULL, PKGMGR_INSTALLER_DBUS_OBJECT_PATH, PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name, - g_variant_new("(usa(sss)ss)", pi->target_uid, sid, - builder, key, val), &err) != TRUE) { + v, &err) != TRUE) { ERR("failed to send dbus signal"); if (err) { ERR("err: %s", err->message); @@ -293,6 +296,7 @@ static int __send_signal_for_event_for_uid(pkgmgr_installer *pi, uid_t uid, (tmp_appid ? tmp_appid : ""), pkg_type); gv = g_variant_new("(usa(sss)ss)", pi->target_uid, sid, builder, key, val); + g_variant_builder_unref(builder); if (gv == NULL) { ERR("failed to create GVariant instance"); return -1; @@ -1138,6 +1142,7 @@ API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid, g_hash_table_foreach(pi->pkg_list, __build_multi_signal, builder); gv = g_variant_new("(usa(sss)ss)", uid, sid, builder, key, val); + g_variant_builder_unref(builder); if (gv == NULL) { ERR("failed to create GVariant instance"); return -1; @@ -1152,6 +1157,7 @@ API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid, data = malloc(data_len); if (data == NULL) { ERR("out of memory"); + g_free(gv_data); return -1; } ptr = data; -- 2.7.4