Fix memory leak which occured when iconv failed
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 3 Feb 2016 07:49:46 +0000 (08:49 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 3 Feb 2016 07:49:46 +0000 (08:49 +0100)
src/libpspp/i18n.c

index 6bdff2a4785734985c2e50e6f5e76b3902c57110..dad224d34da922bd28fc964b5149e9ef03dce3da 100644 (file)
@@ -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;
     }