[patch] Fix BZ 19012 -- memory leak on error path in iconv_open
Paul Pluzhnikov
ppluzhnikov@gmail.com
Sun Sep 27 21:22:00 GMT 2015
Greetings,
Attached patch fixes the leak, but doesn't add a test case.
In order to expose the bug, a partial install (one missing
iconvdata/SJIS.so) is required. I am not sure how to write such a test
case (or even whether it is truly a bug to leak memory when faced with
such a partial install).
Thanks,
2015-09-27 Paul Pluzhnikov <ppluzhnikov@google.com>
[BZ #19012]
* iconv/gconv_db.c (gen_steps): Clean up on error.
--
Paul Pluzhnikov
-------------- next part --------------
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index 4e6ec65..bb9a2bd 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -279,6 +279,12 @@ gen_steps (struct derivation_step *best, const char *toset,
if (shlib_handle == NULL)
{
failed = 1;
+
+ /* Don't leak memory. BZ #19012. */
+ if (step_cnt == 0)
+ free (result[step_cnt].__from_name);
+ free (result[*nsteps - 1].__to_name);
+
break;
}
More information about the Libc-alpha
mailing list