r26498: Fix memory leak in iconv code.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 17 Dec 2007 07:32:00 +0000 (08:32 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:50:54 +0000 (05:50 +0100)
source/lib/charset/charcnv.c
source/lib/charset/iconv.c
source/lib/charset/tests/iconv.c
source/param/loadparm.c
source/torture/smbiconv.c

index 9a4068a4a9899b7fea8f73a2e3e2c4b6c6113695..54a0676599fba6430f23c347f80415e0908f7de4 100644 (file)
@@ -134,7 +134,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
        n1 = charset_name(ic, from);
        n2 = charset_name(ic, to);
 
-       ic->conv_handles[from][to] = smb_iconv_open(n2, n1, ic->native_iconv);
+       ic->conv_handles[from][to] = smb_iconv_open_ex(ic, n2, n1, 
+                                                      ic->native_iconv);
        
        if (ic->conv_handles[from][to] == (smb_iconv_t)-1) {
                if ((from == CH_DOS || to == CH_DOS) &&
@@ -146,8 +147,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
                        n1 = charset_name(ic, from);
                        n2 = charset_name(ic, to);
                        
-                       ic->conv_handles[from][to] = smb_iconv_open(n2, n1,
-                               ic->native_iconv);
+                       ic->conv_handles[from][to] = 
+                               smb_iconv_open_ex(ic, n2, n1, ic->native_iconv);
                }
        }
 
index 937b3ec8b55363de4841ba78895865d34729b7b0..db212a83c42bcac1e1edd6bf9924ac083019f45d 100644 (file)
@@ -154,17 +154,17 @@ static bool is_utf16(const char *name)
                strcasecmp(name, "UTF-16LE") == 0;
 }
 
-/*
-  simple iconv_open() wrapper
- */
-smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode, 
-                          bool native_iconv)
+
+
+smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, 
+                             const char *fromcode, bool native_iconv)
 {
        smb_iconv_t ret;
        const struct charset_functions *from=NULL, *to=NULL;
        int i;
 
-       ret = (smb_iconv_t)talloc_named(NULL, sizeof(*ret), 
+       ret = (smb_iconv_t)talloc_named(mem_ctx,
+                                       sizeof(*ret), 
                                        "iconv(%s,%s)", tocode, fromcode);
        if (!ret) {
                errno = ENOMEM;
@@ -260,6 +260,14 @@ failed:
        return (smb_iconv_t)-1;
 }
 
+/*
+  simple iconv_open() wrapper
+ */
+smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
+{
+       return smb_iconv_open_ex(NULL, tocode, fromcode, true);
+}
+
 /*
   simple iconv_close() wrapper
 */
index d47390b814a64572be372d9673f6cc501b373f47..aeb42c2fa13f84cc4a0c040bfe84282880b391f9 100644 (file)
@@ -157,8 +157,8 @@ static bool test_buffer(struct torture_context *test,
                                                     "failed to open %s to UTF-16LE",
                                                     charset));
                }
-               cd2 = smb_iconv_open(charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true));
-               cd3 = smb_iconv_open("UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true));
+               cd2 = smb_iconv_open_ex(test, charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true));
+               cd3 = smb_iconv_open_ex(test, "UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true));
                last_charset = charset;
        }
 
index d732a09f2f7e7741df53e97fec9937f8144d30dd..6c23a1d520f5f664d171befbe356cfd3f6a95394 100644 (file)
@@ -2466,7 +2466,7 @@ bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
 
        /* FIXME: Check locale in environment for this: */
        if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
-               d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx), true));
+               d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
        else
                d_set_iconv((smb_iconv_t)-1);
 
index 1eb09cae45cbcfb5d7d1bbd9cfe75858af986ac9..4eece66bdf6b8b63b9c71fa99bf853ca624f962d 100644 (file)
@@ -205,7 +205,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       cd = smb_iconv_open(to, from, lp_parm_bool(tctx->lp_ctx, NULL, "iconv", "native", true));
+       cd = smb_iconv_open_ex(tctx, to, from, lp_parm_bool(tctx->lp_ctx, NULL, "iconv", "native", true));
        if((int)cd == -1) {
                DEBUG(0,("unable to find from or to encoding, exiting...\n"));
                return 1;