help-libidn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cppcheck reports Memory leak.


From: Simon Josefsson
Subject: Re: Cppcheck reports Memory leak.
Date: Tue, 24 Feb 2009 10:50:18 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux)

William Egert <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]