[Top][All Lists]
[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 14:37:08 +0100 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux) |
William Egert <address@hidden> writes:
> I agree. I was just testing out that CppCheck software, I will report the
> false positive to them.
>
> Thanks for your understanding! :)
Don't worry, tools like that are very useful and it is important to run
it against libidn to find problems. Thanks for thinking about testing
libidn in this aspect. Setting up auto-mated testing would be useful,
maybe it can help to catch problems introduced in the future.
/Simon
> -Bill
>
> On Tue, Feb 24, 2009 at 4:50 AM, Simon Josefsson <address@hidden>wrote:
>
>> 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
>>