iconv: Use a static buffer in iconf not to spoil the talloc_pool
authorVolker Lendecke <vl@samba.org>
Fri, 6 Dec 2013 10:31:07 +0000 (10:31 +0000)
committerStefan Metzmacher <metze@samba.org>
Sat, 14 Dec 2013 09:06:28 +0000 (10:06 +0100)
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 <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/charset/iconv.c

index 1c507b4b13707d1fd3142d09ef79d58593c1ed69..c5b45fe97535d2d3cd06ab0f46ff9bcb4d6322e7 100644 (file)
@@ -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;