g_variant_unref(body);
}
+static void _free_sticker_data(sticker_info_db *sticker_data)
+{
+ if (!sticker_data)
+ return;
+
+ if (sticker_data->app_id) {
+ free(sticker_data->app_id);
+ sticker_data->app_id = NULL;
+ }
+
+ if (sticker_data->uri) {
+ free(sticker_data->uri);
+ sticker_data->uri = NULL;
+ }
+
+ if (sticker_data->thumbnail) {
+ free(sticker_data->thumbnail);
+ sticker_data->thumbnail = NULL;
+ }
+
+ if (sticker_data->keyword) {
+ g_list_free_full(sticker_data->keyword, free);
+ sticker_data->keyword = NULL;
+ }
+
+ if (sticker_data->group) {
+ free(sticker_data->group);
+ sticker_data->group = NULL;
+ }
+
+ if (sticker_data->description) {
+ free(sticker_data->description);
+ sticker_data->description = NULL;
+ }
+
+ if (sticker_data->date) {
+ free(sticker_data->date);
+ sticker_data->date = NULL;
+ }
+
+ free(sticker_data);
+}
+
int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body)
{
int ret;
continue;
}
- sticker_info->app_id = app_id;
+ sticker_info->app_id = strdup(app_id);
sticker_info->type = _get_int_from_object(info_object, "type");
if (sticker_info->type < 1)
goto free_memory;
_send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info);
free_memory:
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
}
}
ret = stickerd_db_delete_sticker_info(record_id);
if (ret != STICKERD_SERVER_ERROR_NONE) {
LOGE("Failed to delete sticker info");
- return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
} else {
- if (sticker_info && sticker_info->uri) {
+ if (sticker_info && sticker_info->uri)
_send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info);
- free(sticker_info);
- sticker_info = NULL;
- }
+ }
+
+ if (sticker_info) {
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
}
return ret;
ret = stickerd_db_delete_sticker_info_by_uri(uri);
if (ret != STICKERD_SERVER_ERROR_NONE) {
LOGE("Failed to delete sticker info");
- return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
} else {
- if (sticker_info && sticker_info->uri) {
+ if (sticker_info && sticker_info->uri)
_send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info);
- free(sticker_info);
- sticker_info = NULL;
- }
+ }
+
+ if (sticker_info) {
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
}
return ret;
ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
if (ret != STICKERD_SERVER_ERROR_NONE) {
LOGE("Failed to get sticker info");
-
- if (sticker_info->app_id)
- free(sticker_info->app_id);
-
- if (sticker_info->uri)
- free(sticker_info->uri);
-
- if (sticker_info->thumbnail)
- free(sticker_info->thumbnail);
-
- if (sticker_info->keyword)
- free(sticker_info->keyword);
-
- if (sticker_info->group)
- free(sticker_info->group);
-
- if (sticker_info->description)
- free(sticker_info->description);
-
- if (sticker_info->date)
- free(sticker_info->date);
-
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
return STICKERD_SERVER_ERROR_OPERATION_FAILED;
}
if (*reply_body == NULL) {
LOGE("Failed to create reply_body");
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
return STICKERD_SERVER_ERROR_OPERATION_FAILED;
}
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
+
return ret;
}
sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
if (sticker_info) {
ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
- if (ret == STICKERD_SERVER_ERROR_NONE) {
+ if (ret == STICKERD_SERVER_ERROR_NONE)
_send_sticker_changed_event(STICKER_EVENT_TYPE_UPDATE, sticker_info);
- free(sticker_info);
- sticker_info = NULL;
- }
+
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
}
return ret;