From: Philipp Gesang Date: Mon, 10 Jan 2022 14:27:12 +0000 (+0100) Subject: don't leak iconv context on OOM X-Git-Tag: v2.12~9 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=858cd10b4a51801e7639b146a9ca6bacda6bc273;p=libi2ncommon don't leak iconv context on OOM --- diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index d611abf..7108bc9 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -795,7 +795,10 @@ std::string iso_to_utf8(const std::string& isostring) char *buf = (char *)malloc(out_size+1); if (buf == NULL) + { + iconv_close(i2utf8); throw runtime_error("out of memory for iconv buffer"); + } char *in = (char *)isostring.c_str(); char *out = buf; @@ -825,7 +828,10 @@ std::string utf8_to_iso(const std::string& utf8string) char *buf = (char *)malloc(out_size+1); if (buf == NULL) + { + iconv_close(utf82iso); throw runtime_error("out of memory for iconv buffer"); + } char *in = (char *)utf8string.c_str(); char *out = buf; @@ -853,7 +859,10 @@ wchar_t* utf8_to_wbuf(const std::string& utf8string) wchar_t *buf = (wchar_t *)malloc(out_size); if (buf == NULL) + { + iconv_close(utf82wstr); throw runtime_error("out of memory for iconv buffer"); + } char *in = (char *)utf8string.c_str(); char *out = (char*) buf; @@ -881,7 +890,10 @@ std::string utf7imap_to_utf8(const std::string& utf7imapstring) char *buf = (char *)malloc(out_size+1); if (buf == NULL) + { + iconv_close(utf7imap2utf8); throw runtime_error("out of memory for iconv buffer"); + } char *in = (char *)utf7imapstring.c_str(); char *out = buf; @@ -913,7 +925,10 @@ std::string utf8_to_utf7imap(const std::string& utf8string) char *buf = (char *)malloc(out_size+1); if (buf == NULL) + { + iconv_close(utf82utf7imap); throw runtime_error("out of memory for iconv buffer"); + } char *in = (char *)utf8string.c_str(); char *out = buf;