From 562e1107b3aa705a987ab912014926068e29470e Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 3 Feb 2016 08:49:46 +0100 Subject: [PATCH] Fix memory leak which occured when iconv failed --- src/libpspp/i18n.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index 6bdff2a478..dad224d34d 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -82,7 +82,7 @@ create_iconv (const char* tocode, const char* fromcode) converter->tocode = xstrdup (tocode); converter->fromcode = xstrdup (fromcode); converter->conv = iconv_open (tocode, fromcode); - int error = converter->conv == (iconv_t) -1 ? errno : 0; + int error = converter->conv == (iconv_t) ~0 ? errno : 0; /* I don't think it's safe to translate this string or to use messaging as the converters have not yet been set up */ if (error && strcmp (tocode, fromcode)) @@ -92,6 +92,10 @@ create_iconv (const char* tocode, const char* fromcode) "cannot create a converter for `%s' to `%s': %s\n", fromcode, tocode, strerror (error)); + free (converter->tocode); + free (converter->fromcode); + free (converter); + hmapx_insert (&map, NULL, hash); return NULL; } -- 2.30.2