#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;
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();
outp = dest = static_cast<gchar*>(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;
have_error = TRUE;
}
- g_iconv_close(cd);
-
std::string result;
if (!have_error) {
LoggerE("Conversion error");
}
- g_free(dest);
-
return result;
}