William Egert <[email protected]> writes:

> Running http://cppcheck.wiki.sourceforge.net/ reports:
>
> [lib/toutf8.c:122]: (always) Memory leak: p
>
> for version 1.12 of libidn

Hi.  Thanks for the report.  I would say it is a false positive, the
code reads:

...
 * Return value: Returns newly allocated zero-terminated string which
 *   is @str transcoded into to_codeset.
 **/
char *
stringprep_convert (const char *str,
                    const char *to_codeset, const char *from_codeset)
{
#if HAVE_ICONV
  return str_iconv (str, from_codeset, to_codeset);
#else
  char *p;
  fprintf (stderr, "libidn: warning: libiconv not installed, cannot "
           "convert data to UTF-8\n");
  p = malloc (strlen (str) + 1);
  if (!p)
    return NULL;
  return strcpy (p, str);
#endif
}

I'm assuming you've tested the !HAVE_ICONV code path.

The function is documented to return a pointer to newly allocated
storage.  If the function is used as documented, and the caller
de-allocate the string after use, I don't see how there is a memory
leak.  What do you think?

/Simon


_______________________________________________
Help-libidn mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-libidn

Reply via email to