[Contact] Fixed memory leak in ContactManagerImportFromVCard.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 8 Jun 2015 12:48:51 +0000 (14:48 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 8 Jun 2015 12:48:51 +0000 (14:48 +0200)
Prevent CID: 395213

[Verification] TCT pass rate 441/441.

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

index 95452c2..4fc8209 100755 (executable)
 #include <set>
 
 #include "common/converter.h"
-#include "common/picojson.h"
-#include "common/logger.h"
 #include "common/filter-utils.h"
+#include "common/logger.h"
+#include "common/picojson.h"
+#include "common/scope_exit.h"
 
 #include <contacts.h>
 #include <contacts_db_extension.h>
@@ -786,10 +787,13 @@ PlatformResult ContactManagerImportFromVCard(const JsonObject& args,
                           "Fail to convert vCard from string");
   }
 
+  SCOPE_EXIT {
+    contacts_list_destroy(contacts_list, true);
+  };
+
   int record_count = 0;
   err = contacts_list_get_count(contacts_list, &record_count);
   if (CONTACTS_ERROR_NONE != err || 0 == record_count) {
-    contacts_list_destroy(contacts_list, true);
     LoggerE("Invalid vCard string.");
     return PlatformResult(ErrorCode::UNKNOWN_ERR, "Invalid vCard string.");
   }
@@ -798,7 +802,6 @@ PlatformResult ContactManagerImportFromVCard(const JsonObject& args,
   contacts_list_first(contacts_list);
   err = contacts_list_get_current_record_p(contacts_list, &contacts_record);
   if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
-    contacts_list_destroy(contacts_list, true);
     LoggerE("Invalid vCard string.");
     return PlatformResult(ErrorCode::UNKNOWN_ERR, "Invalid vCard string.");
   }