diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-12-17 08:32:00 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-21 05:50:54 +0100 |
commit | 01b96e47cd77c345ac27c4c882e353852e49f22b (patch) | |
tree | 8ecaaa7fa3d542fff25ace2a4086e3ba0dbcfc89 /source4/lib/charset | |
parent | 83655ec0dd58c21cdb99d5e7c8008b4b3087449b (diff) | |
download | samba-01b96e47cd77c345ac27c4c882e353852e49f22b.tar.gz samba-01b96e47cd77c345ac27c4c882e353852e49f22b.tar.bz2 samba-01b96e47cd77c345ac27c4c882e353852e49f22b.zip |
r26498: Fix memory leak in iconv code.
(This used to be commit 8795697db56e4ca6715950d68f5ec370604fcc76)
Diffstat (limited to 'source4/lib/charset')
-rw-r--r-- | source4/lib/charset/charcnv.c | 7 | ||||
-rw-r--r-- | source4/lib/charset/iconv.c | 20 | ||||
-rw-r--r-- | source4/lib/charset/tests/iconv.c | 4 |
3 files changed, 20 insertions, 11 deletions
diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 9a4068a4a9..54a0676599 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -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); } } diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 937b3ec8b5..db212a83c4 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -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; @@ -261,6 +261,14 @@ failed: } /* + 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 */ int smb_iconv_close(smb_iconv_t cd) diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index d47390b814..aeb42c2fa1 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -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; } |