From: Pawel Andruszkiewicz
Date: Mon, 8 Jun 2015 10:07:40 +0000 (+0200)
Subject: [Contact] Added nullptr checks, improved memory handling.
X-Git-Tag: submit/tizen_mobile/20150612.133019^2~2^2~37^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d779798b5fa2c763614e550cad0c0869b9c8485c;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Contact] Added nullptr checks, improved memory handling.
Prevent CID: 403116
[Verification] TCT pass rate: 441/441.
Change-Id: I208f343a6513d09bb82d9d45e43be24b750db38e
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/contact/addressbook.cc b/src/contact/addressbook.cc
index 04d21997..631612c2 100755
--- a/src/contact/addressbook.cc
+++ b/src/contact/addressbook.cc
@@ -18,8 +18,9 @@
#include "common/converter.h"
#include "common/extension.h"
-#include "common/platform_exception.h"
#include "common/logger.h"
+#include "common/platform_exception.h"
+#include "common/scope_exit.h"
#include
#include "contact/contact_instance.h"
@@ -263,16 +264,18 @@ PlatformResult AddressBookAddBatch(const JsonObject& args, JsonArray& out) {
int* ids = nullptr;
int count = 0;
+
+ SCOPE_EXIT {
+ free(ids);
+ };
+
error_code = contacts_db_insert_records(*contacts_list_ptr, &ids, &count);
- if (CONTACTS_ERROR_NONE != error_code) {
- if (ids) {
- free(ids);
- ids = NULL;
- }
+ if (CONTACTS_ERROR_NONE != error_code || nullptr == ids) {
LoggerE("inserting contacts to db fails, code: %d", error_code);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"inserting contacts to db fails");
}
+
if (length != count) {
LoggerW("Added different number of contacts");
}
@@ -283,10 +286,6 @@ PlatformResult AddressBookAddBatch(const JsonObject& args, JsonArray& out) {
error_code =
contacts_db_get_record(_contacts_contact._uri, ids[i], &contact_record);
if (CONTACTS_ERROR_NONE != error_code) {
- if (ids) {
- free(ids);
- ids = NULL;
- }
LoggerW("Contacts record get error, error code: %d", error_code);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"Contacts record get error");
@@ -297,10 +296,6 @@ PlatformResult AddressBookAddBatch(const JsonObject& args, JsonArray& out) {
out.push_back(JsonValue{out_object});
}
- if (ids) {
- free(ids);
- ids = NULL;
- }
return PlatformResult(ErrorCode::NO_ERROR);
}