From b6978bad1d52b2666750a2302d882856cc5f4dd4 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 28 Aug 2015 14:49:16 +0900 Subject: [PATCH] Fix memory leak free locale string free pkginfo_x, appinfo_x in error case Change-Id: I71693d53478b5e21e0d9f6d9d6e7b89ee80df51c Signed-off-by: Sangyoon Jang --- src/pkgmgrinfo_appinfo.c | 14 ++++++++++---- src/pkgmgrinfo_pkginfo.c | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index d8ca7b0..c681971 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -204,6 +204,8 @@ static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, *list = g_list_delete_link(*list, tmp); } + free(locale); + return PMINFO_R_OK; } @@ -700,14 +702,18 @@ static int _appinfo_get_appinfo(const char *appid, uid_t uid, } ret = _appinfo_get_application(db, appid, locale, &info->app_info); - if (ret == PMINFO_R_OK) { - info->locale = strdup(locale); - info->package = strdup(info->app_info->package); + if (ret != PMINFO_R_OK) { + free(info); + free(locale); + sqlite3_close_v2(db); + return ret; } + info->locale = locale; + info->package = strdup(info->app_info->package); + *appinfo = info; - free(locale); sqlite3_close_v2(db); return ret; diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index 6f86951..932ebdd 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -310,6 +310,8 @@ static int _pkginfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, *list = g_list_delete_link(*list, tmp); } + free(locale); + return PMINFO_R_OK; } @@ -817,16 +819,20 @@ static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid, } ret = _pkginfo_get_package(db, pkgid, locale, &info->pkg_info); - if (ret == PMINFO_R_OK) { - info->locale = strdup(locale); - info->uid = uid; - info->pkg_info->for_all_users = strdup( - uid != GLOBAL_USER ? "false" : "true"); + if (ret != PMINFO_R_OK) { + free(info); + free(locale); + sqlite3_close_v2(db); + return ret; } + info->locale = locale; + info->uid = uid; + info->pkg_info->for_all_users = strdup( + uid != GLOBAL_USER ? "false" : "true"); + *pkginfo = info; - free(locale); sqlite3_close_v2(db); return ret; -- 2.7.4