I use realloc to resize the memory allocated:
char **get_channel_name(void)
{
char **result;
int n;
result = (char **) 0;
for (elem = snd
If realloc() fails it returns NULL.
So if you do (and assuming realloc() would fail)
result = realloc(result, ...);
result will be assigned NULL and what it pointed to is not free()ed and the address to be free()ed is lost.
To fix this do:
{
void * tmp = realloc(result, ...);
if (NULL == tmp)
{
/* Handle error case, propably freeing what result is pointing to. */
}
else
{
result = tmp;
}
}