From: Pawel Andruszkiewicz
Date: Tue, 9 Jun 2015 13:13:59 +0000 (+0200)
Subject: [Messaging] Fixed memory handling in convertPlatformEmail().
X-Git-Tag: submit/tizen_mobile/20150612.133019^2~2^2~14^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef727e4513e881bf133277a7d2e0ddc07b6ad18f;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Messaging] Fixed memory handling in convertPlatformEmail().
Prevent CID: 403650
[Verification] Pass rate should not change.
Change-Id: Ib7ae514ab34a61ed8d8c036af8b34d3f4d0b5c98
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/messaging/message.cc b/src/messaging/message.cc
index 975f6781..2aad6e52 100755
--- a/src/messaging/message.cc
+++ b/src/messaging/message.cc
@@ -474,11 +474,17 @@ PlatformResult Message::convertPlatformEmail(std::shared_ptr message,
if(message->is_id_set()) {
email_get_mail_data(message->getId(), &mail_data);
} else {
- mail_data = (email_mail_data_t*)malloc(
- sizeof(email_mail_data_t));
+ mail_data = (email_mail_data_t*)malloc(sizeof(email_mail_data_t));
+ if (!mail_data) {
+ LoggerE("malloc failure");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to allocate memory.");
+ }
memset(mail_data, 0x00, sizeof(email_mail_data_t));
}
+ std::unique_ptr mail_data_ptr(
+ mail_data, [](email_mail_data_t* mail) {email_free_mail_data(&mail, 1);});
+
if(!message->getFrom().empty()) {
std::string from = "<"+message->getFrom()+">";
mail_data->full_address_from = strdup(from.c_str());
@@ -516,8 +522,6 @@ PlatformResult Message::convertPlatformEmail(std::shared_ptr message,
if(!mail_data->file_path_plain)
{
LoggerE("Plain Body file is NULL.");
- free(mail_data);
- mail_data = NULL;
return PlatformResult(ErrorCode::UNKNOWN_ERR, "Plain Body file is NULL.");
}
}
@@ -529,8 +533,6 @@ PlatformResult Message::convertPlatformEmail(std::shared_ptr message,
if(!mail_data->file_path_html)
{
LoggerE("Html Body file is NULL.");
- free(mail_data);
- mail_data = NULL;
return PlatformResult(ErrorCode::UNKNOWN_ERR, "Html Body file is NULL.");
}
} else if(!body->getPlainBody().empty()) {
@@ -541,8 +543,6 @@ PlatformResult Message::convertPlatformEmail(std::shared_ptr message,
if(!mail_data->file_path_html)
{
LoggerE("Plain Body file is NULL.");
- free(mail_data);
- mail_data = NULL;
return PlatformResult(ErrorCode::UNKNOWN_ERR, "Plain Body file is NULL.");
}
}
@@ -556,7 +556,7 @@ PlatformResult Message::convertPlatformEmail(std::shared_ptr message,
mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL;
}
- *result_mail_data = mail_data;
+ *result_mail_data = mail_data_ptr.release(); // release ownership
return PlatformResult(ErrorCode::NO_ERROR);
}