From: Pawel Andruszkiewicz
Date: Fri, 4 Sep 2015 08:33:24 +0000 (+0200)
Subject: [Contact] Manage the memory of 'groups_list' variable.
X-Git-Tag: submit/tizen/20151026.073646^2^2~138^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f5ebb3fb014965e7f551c90e202ae62469f826e;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Contact] Manage the memory of 'groups_list' variable.
Prevent CID: 476710
[Verification] TCT pass rate (r38): 100% (441/441/0/0/0).
Change-Id: I0942b4a31e0786f7eac761de6cf9b3b4e79074b6
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/contact/addressbook.cc b/src/contact/addressbook.cc
index b656e368..2882a112 100755
--- a/src/contact/addressbook.cc
+++ b/src/contact/addressbook.cc
@@ -642,6 +642,10 @@ PlatformResult AddressBookGetGroups(const JsonObject& args, JsonArray& out) {
err, "Fail to get contacts_db_get_records_with_query ");
if (status.IsError()) return status;
+ // deleter to release the memory in case of an error
+ ContactUtil::ContactsListHPtr group_list_ptr(
+ &groups_list, ContactUtil::ContactsListDeleter);
+
err = contacts_filter_destroy(filter);
status =
ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_destroy ");
@@ -651,7 +655,15 @@ PlatformResult AddressBookGetGroups(const JsonObject& args, JsonArray& out) {
status =
ContactUtil::ErrorChecker(err, "Fail to get contacts_query_destroy ");
if (status.IsError()) return status;
+
+ // release the ownership, pass it back to the outer scope
+ group_list_ptr.release();
}
+
+ // groups_list has been initialized, take the ownership
+ ContactUtil::ContactsListHPtr group_list_ptr(
+ &groups_list, ContactUtil::ContactsListDeleter);
+
int record_count = 0;
err = contacts_list_get_count(groups_list, &record_count);
status =