Hello Marcelo,

Thanks for working on that :)

>  
>  tofree = string = strdup("abc,def,ghi");
> -assert(string != NULL);
> +if (string != NULL)
> +     while ((token = strsep(&string, ",")) != NULL)
> +             printf("%s\en", token);
Please notice:
```
If *stringp is initially NULL, strsep() returns NULL.
```
So I even not sure if you need to check strdup() at this point.

>  
> -while ((token = strsep(&string, ",")) != NULL)
> -     printf("%s\en", token);
> -
>  free(tofree);
> +free(string);
Here you introduced potential double free.
At the end of loop the 'string' will be equals to NULL so there is no point to
free it. If somebody would use this code as example and he from any other reason
would stop at any other point the string will be pointing to the middle of
'tofree' variable which you already freed.

Thanks,
-- 
Mariusz Zaborski
oshogbo//vx             | http://oshogbo.vexillium.org
FreeBSD commiter        | https://freebsd.org
Software developer      | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1

Attachment: signature.asc
Description: PGP signature

Reply via email to