summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjusung son <jusung07.son@samsung.com>2018-07-03 10:43:18 +0900
committerjusung son <jusung07.son@samsung.com>2018-07-03 10:43:18 +0900
commite17f307e86268e2644296a711def8ad659c9276a (patch)
tree677d08a2c3bb1d7bbf33bbdc9e2c5203698d242e
parent5b947601d2ff23321ba2505a5f796703b3860a57 (diff)
downloadshortcut-e17f307e86268e2644296a711def8ad659c9276a.tar.gz
shortcut-e17f307e86268e2644296a711def8ad659c9276a.tar.bz2
shortcut-e17f307e86268e2644296a711def8ad659c9276a.zip
Fix resource leak
Change-Id: Ifb5051be6538e276e21444fef740df029f5ee724 Signed-off-by: jusung son <jusung07.son@samsung.com>
-rwxr-xr-xlib/src/shortcut_manager.c71
1 files changed, 27 insertions, 44 deletions
diff --git a/lib/src/shortcut_manager.c b/lib/src/shortcut_manager.c
index 6499489..12ff3ad 100755
--- a/lib/src/shortcut_manager.c
+++ b/lib/src/shortcut_manager.c
@@ -142,10 +142,10 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type,
const char *uri, const char *icon, int allow_duplicate,
result_cb cb, void *data)
{
- struct result_cb_item *item;
- char *appid;
+ struct result_cb_item *item = NULL;
+ char *appid = NULL;
int ret;
- GVariant *body;
+ GVariant *body = NULL;
char *request_id = NULL;
CHECK_SHORTCUT_FEATURE();
@@ -161,18 +161,16 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type,
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
SHORTCUT_ERR("ready to send error [%d]", ret);
- return ret;
+ goto out;
/* LCOV_EXCL_STOP */
}
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
- if (appid)
- free(appid);
-
SHORTCUT_ERR("Heap: %d\n", errno);
- return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ ret = SHORTCUT_ERROR_OUT_OF_MEMORY;
+ goto out;
/* LCOV_EXCL_STOP */
}
@@ -193,19 +191,16 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type,
type, uri, icon, allow_duplicate);
ret = _send_async_shortcut(body, item, "add_shortcut");
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- free(item);
- item = NULL;
- /* LCOV_EXCL_STOP */
- }
+out:
if (appid)
free(appid);
if (body)
g_variant_unref(body);
if (request_id)
free(request_id);
+ if (ret != SHORTCUT_ERROR_NONE && item)
+ free(item);
return ret;
}
@@ -214,10 +209,10 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
const char *widget_id, const char *icon, double period,
int allow_duplicate, result_cb cb, void *data)
{
- struct result_cb_item *item;
- char *appid;
+ struct result_cb_item *item = NULL;
+ char *appid = NULL;
int ret;
- GVariant *body;
+ GVariant *body = NULL;
char *request_id = NULL;
CHECK_SHORTCUT_FEATURE();
@@ -238,18 +233,16 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
SHORTCUT_ERR("ready to send error [%d]", ret);
- return ret;
+ goto out;
/* LCOV_EXCL_STOP */
}
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
- if (appid)
- free(appid);
-
SHORTCUT_ERR("Heap: %d\n", errno);
- return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ ret = SHORTCUT_ERROR_OUT_OF_MEMORY;
+ goto out;
/* LCOV_EXCL_STOP */
}
@@ -262,29 +255,25 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
ret = _send_async_shortcut(body, item, "add_shortcut_widget");
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- free(item);
- item = NULL;
- /* LCOV_EXCL_STOP */
- }
-
+out:
if (appid)
free(appid);
if (body)
g_variant_unref(body);
if (request_id)
free(request_id);
+ if (ret != SHORTCUT_ERROR_NONE && item)
+ free(item);
return ret;
}
EAPI int shortcut_remove_from_home(const char *name, result_cb cb, void *user_data)
{
- struct result_cb_item *item;
- char *appid;
+ struct result_cb_item *item = NULL;
+ char *appid = NULL;
int ret;
- GVariant *body;
+ GVariant *body = NULL;
char *request_id = NULL;
CHECK_SHORTCUT_FEATURE();
@@ -298,18 +287,16 @@ EAPI int shortcut_remove_from_home(const char *name, result_cb cb, void *user_da
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
SHORTCUT_ERR("ready to send error [%d]", ret);
- return ret;
+ goto out;
/* LCOV_EXCL_STOP */
}
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
- if (appid)
- free(appid);
-
SHORTCUT_ERR("Heap: %d\n", errno);
- return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ ret = SHORTCUT_ERROR_OUT_OF_MEMORY;
+ goto out;
/* LCOV_EXCL_STOP */
}
@@ -320,20 +307,16 @@ EAPI int shortcut_remove_from_home(const char *name, result_cb cb, void *user_da
body = g_variant_new("(siss)", request_id, getpid(), appid, name);
ret = _send_async_shortcut(body, item, "remove_shortcut");
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- free(item);
- item = NULL;
- /* LCOV_EXCL_STOP */
- }
+out:
if (appid)
free(appid);
if (body)
g_variant_unref(body);
if (request_id)
free(request_id);
-
+ if (ret != SHORTCUT_ERROR_NONE && item)
+ free(item);
return ret;
}