From: Pawel Andruszkiewicz
Date: Wed, 26 Aug 2015 07:21:05 +0000 (+0200)
Subject: [MessagingEmail] Make sure that resources are freed in case of error.
X-Git-Tag: submit/tizen/20151026.073646^2^2~167
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef50aed3d99be15f4d03cfb28301a617053d7ff4;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[MessagingEmail] Make sure that resources are freed in case of error.
Prevent CID: 476172
[Verification] TCT pass rate (r35): 100% (308/308/0/0/0).
Change-Id: I7df6af7127de24b2eb712693f890c69889c956d9
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc
index 6cb875df..fc2cd94e 100755
--- a/src/messaging/messaging_util.cc
+++ b/src/messaging/messaging_util.cc
@@ -35,6 +35,7 @@
#include "tizen/tizen.h"
#include "common/logger.h"
#include "common/platform_exception.h"
+#include "common/scope_exit.h"
#include "common/assert.h"
using common::ErrorCode;
@@ -317,9 +318,13 @@ std::string PerformConversion(const std::string& input, const gchar* from_charse
if ((GIConv)-1 == cd) {
LoggerE("Failed to open iconv.");
- return "";
+ return input;
}
+ SCOPE_EXIT {
+ g_iconv_close(cd);
+ };
+
// copied from glib/gconvert.c, g_convert does not handle "//IGNORE" properly
static const gsize kNulTerminatorLength = 4;
const gchar* str = input.c_str();
@@ -337,11 +342,15 @@ std::string PerformConversion(const std::string& input, const gchar* from_charse
outp = dest = static_cast(g_malloc(outbuf_size));
- if (!outp) {
+ if (!dest) {
LoggerE("Failed to allocate memory.");
return input;
}
+ SCOPE_EXIT {
+ g_free(dest);
+ };
+
while (!done && !have_error) {
gsize err = 0;
@@ -404,8 +413,6 @@ std::string PerformConversion(const std::string& input, const gchar* from_charse
have_error = TRUE;
}
- g_iconv_close(cd);
-
std::string result;
if (!have_error) {
@@ -414,8 +421,6 @@ std::string PerformConversion(const std::string& input, const gchar* from_charse
LoggerE("Conversion error");
}
- g_free(dest);
-
return result;
}