Fix crash issue 18/223518/2
authorInHong Han <inhong1.han@samsung.com>
Thu, 30 Jan 2020 10:50:47 +0000 (19:50 +0900)
committerInHong Han <inhong1.han@samsung.com>
Thu, 30 Jan 2020 11:01:48 +0000 (20:01 +0900)
If the GDBusMessage created using GVariant, GDBusMessage has an ownership of GVariant.
Therefore it is not necessary to free the memory of the GVariant.

Change-Id: I6d84b66343a3a2494eb723d60f36180a1d2bdd44

client/sticker_dbus.c
server/stickerd_data_manager.c

index 627fe46..7984351 100644 (file)
@@ -530,11 +530,9 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id
 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id)
 {
     int ret;
-    GVariant *body = NULL;
 
     if (server_watcher_id) {
-        body = g_variant_new("(i)", *server_watcher_id);
-        ret = _send_async_message(gdbus_connection, body, "sticker_service_unregister");
+        ret = _send_async_message(gdbus_connection, g_variant_new("(i)", *server_watcher_id), "sticker_service_unregister");
         if (ret != STICKER_CLIENT_ERROR_NONE) {
             LOGE("Failed to unregister sticker service");
             return ret;
@@ -553,9 +551,6 @@ int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher
         *monitor_id = 0;
     }
 
-    if (body)
-        g_variant_unref(body);
-
     return STICKER_CLIENT_ERROR_NONE;
 }
 
@@ -574,7 +569,6 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
     int ret;
     int ret_id = -1;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     GVariantBuilder *info_builder;
     GVariantBuilder *keyword_builder;
@@ -595,12 +589,7 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
     keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
     g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
 
-    body = g_variant_new("(a{iv}a(s))", info_builder, keyword_builder);
-
-    g_variant_builder_unref(info_builder);
-    g_variant_builder_unref(keyword_builder);
-
-    ret = _send_sync_message(gdbus_connection, body, &reply, "insert_sticker_info");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
     if (ret != STICKER_CLIENT_ERROR_NONE) {
         LOGW("Failed to save sticker info");
         return ret;
@@ -611,8 +600,9 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
     sticker_data->sticker_info_id = ret_id;
 
     LOGD("ret_id : %d", ret_id);
-    if (body)
-        g_variant_unref(body);
+
+    g_variant_builder_unref(info_builder);
+    g_variant_builder_unref(keyword_builder);
 
     if (reply_body)
         g_variant_unref(reply_body);
@@ -626,16 +616,11 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
 {
     int ret;
-    GVariant *body = NULL;
 
-    body = g_variant_new("(ss)", app_id, json_path);
-    ret = _send_async_message(gdbus_connection, body, "update_sticker_info_by_json");
+    ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
     if (ret != STICKER_CLIENT_ERROR_NONE)
         LOGE("failed to send json path");
 
-    if (body)
-        g_variant_unref(body);
-
     return ret;
 }
 
@@ -643,16 +628,11 @@ int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int reco
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
 
-    body = g_variant_new("(i)", record_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "delete_sticker_info");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
     if (ret != STICKER_CLIENT_ERROR_NONE)
         LOGE("failed to delete sticker info");
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply)
         g_object_unref(reply);
 
@@ -663,7 +643,6 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
 
@@ -672,9 +651,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
         return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
     }
 
-    body = g_variant_new("(i)", sticker_data->sticker_info_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         _get_sticker_info_from_gvariant(reply_body, origin_data);
@@ -683,72 +660,56 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
         free(origin_data);
         if (reply)
             g_object_unref(reply);
-        if (body)
-            g_variant_unref(body);
         return ret;
     }
 
     if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
         LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
-        g_variant_unref(body);
-        body = g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_type");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker type");
     }
 
     if (sticker_data->uri && strcmp(sticker_data->uri, origin_data->uri) != 0) {
         LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, sticker_data->uri);
-        g_variant_unref(body);
-        body = g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_uri");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker uri");
     }
 
     if (sticker_data->thumbnail && strcmp(sticker_data->thumbnail, origin_data->thumbnail) != 0) {
         LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, sticker_data->thumbnail);
-        g_variant_unref(body);
-        body = g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_thumbnail");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker thumbnail");
     }
 
     if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
         LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
-        g_variant_unref(body);
-        body = g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_description");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker description");
     }
 
     if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
         LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
-        g_variant_unref(body);
-        body = g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_group");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker group");
     }
 
     if (sticker_data->keyword) {
         GVariantBuilder *keyword_builder;
-        g_variant_unref(body);
         keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
         g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
-        body = g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_keyword");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker keyword");
+        g_variant_builder_unref(keyword_builder);
     }
 
     _free_sticker_data(origin_data);
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -762,12 +723,9 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(i)", record_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         sticker_data->sticker_info_id = record_id;
@@ -777,9 +735,6 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection
             g_variant_unref(reply_body);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply)
         g_object_unref(reply);
 
@@ -791,7 +746,6 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group
     int ret;
     GDBusMessage *reply = NULL;
     GVariantIter *iter = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     char *group = NULL;
 
@@ -800,9 +754,7 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group
         return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
     }
 
-    body = g_variant_new("()");
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_group_list");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "get_group_list");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(s))", &iter);
@@ -819,9 +771,6 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group
         g_variant_iter_free(iter);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -836,7 +785,6 @@ int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **key
     int ret;
     GDBusMessage *reply = NULL;
     GVariantIter *iter = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     char *keyword = NULL;
 
@@ -845,9 +793,7 @@ int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **key
         return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
     }
 
-    body = g_variant_new("()");
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_keyword_list");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "get_keyword_list");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(s))", &iter);
@@ -864,9 +810,6 @@ int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **key
         g_variant_iter_free(iter);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -880,20 +823,14 @@ int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(s)", app_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_count");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(i)", count);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -907,19 +844,14 @@ int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, int off
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(ii)", offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_all_sticker_info");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", offset, count), &reply, "get_all_sticker_info");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(i))", &(*id_iter));
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -933,19 +865,14 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(sii)", app_id, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_appid");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(i))", &(*id_iter));
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -959,19 +886,14 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, sti
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(iii)", (int)type, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_type");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(iii)", (int)type, offset, count), &reply, "get_sticker_info_by_type");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(i))", &(*id_iter));
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -985,19 +907,14 @@ int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, co
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(sii)", group, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_group");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", group, offset, count), &reply, "get_sticker_info_by_group");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(i))", &(*id_iter));
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -1011,19 +928,14 @@ int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection,
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(sii)", keyword, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_keyword");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", keyword, offset, count), &reply, "get_sticker_info_by_keyword");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(i))", &(*id_iter));
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
index ef332a2..6581922 100644 (file)
@@ -149,9 +149,6 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con
         g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, ret, "sticker error");
     }
 
-    if (reply_body)
-        g_variant_unref(reply_body);
-
     _check_watcher_exist();
 }