From 858cd10b4a51801e7639b146a9ca6bacda6bc273 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 10 Jan 2022 15:27:12 +0100 Subject: [PATCH] don't leak iconv context on OOM --- src/stringfunc.cpp | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) 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; -- 1.7.1