From 70dfb51430bc3b6e436fb5c5452d7ef8612ca02f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 6 Dec 2013 10:31:07 +0000 Subject: [PATCH] iconv: Use a static buffer in iconf not to spoil the talloc_pool This is a buffer that is strictly used like a stack variable. This patch makes it one and while there it fixes an error path memleak. In the "pull_failed" case we did not talloc_free(cvtbuf). With talloc_tos(), this does not really matter, but for code without this it does. Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- lib/util/charset/iconv.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/util/charset/iconv.c b/lib/util/charset/iconv.c index 1c507b4b137..c5b45fe9753 100644 --- a/lib/util/charset/iconv.c +++ b/lib/util/charset/iconv.c @@ -127,20 +127,8 @@ _PUBLIC_ size_t smb_iconv(smb_iconv_t cd, #ifndef SMB_ICONV_BUFSIZE #define SMB_ICONV_BUFSIZE 2048 #endif - TALLOC_CTX *mem_ctx; size_t bufsize; - char *cvtbuf; - -#if _SAMBA_BUILD_ == 3 - mem_ctx = talloc_tos(); -#else - mem_ctx = cd; -#endif - cvtbuf = talloc_array(mem_ctx, char, SMB_ICONV_BUFSIZE); - - if (!cvtbuf) { - return (size_t)-1; - } + char cvtbuf[SMB_ICONV_BUFSIZE]; while (*inbytesleft > 0) { char *bufp1 = cvtbuf; @@ -161,7 +149,6 @@ _PUBLIC_ size_t smb_iconv(smb_iconv_t cd, if (cd->push(cd->cd_push, &bufp2, &bufsize, outbuf, outbytesleft) == -1) { - talloc_free(cvtbuf); return -1; } else if (pull_failed) { /* We want the pull errno if possible */ @@ -169,7 +156,6 @@ _PUBLIC_ size_t smb_iconv(smb_iconv_t cd, return -1; } } - talloc_free(cvtbuf); } return 0; -- 2.11.4.GIT