[Contact] Manage the memory of 'groups_list' variable.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 4 Sep 2015 08:33:24 +0000 (10:33 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 4 Sep 2015 08:33:24 +0000 (10:33 +0200)
Prevent CID: 476710

[Verification] TCT pass rate (r38): 100% (441/441/0/0/0).

Change-Id: I0942b4a31e0786f7eac761de6cf9b3b4e79074b6
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/contact/addressbook.cc

index b656e36894e561eeb6aba5503d82a7692c7e8736..2882a11210c1d694ab8e7921f961483069cf6f88 100755 (executable)
@@ -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 =