[Metakit] Re: Win CE problem

Helmut Giese hgiese at ratiosoft.com
Wed Feb 11 13:04:01 CET 2004


>
>void c4_StringArray::SetAt(int nIndex, const char* newElement)
>{
>   char* s = (char*) _ptrs.GetAt(nIndex);
>   if (s && *s)
>     free(s);
>
>   _ptrs.SetAt(nIndex, newElement && *newElement? _strdup(newElement) : "");
>}

Hi,
to me the
         if (s && *s)
looks suspicious:
Imagine you have an empty string: char *p = "";
If you were to say
         char *q = strdup( p);
I am rather certain, that
         *q == '\0'

If this is true, the condition above will fail for any such string, 'free' 
wouldn't get called and you'd have a small leak.

HTH
Helmut Giese



More information about the Metakit mailing list