Memory leak in error scenario.
Brought to you by:
davegamble
During code walkthrough, I noticed in print_object function if the print_value function fails the function is returning without freeing the str pointer from the print_str_ptr(child->string) function.
Thanks
Suriya.
static char *print_object(cJSON *item,int depth)
{
char *out,*ptr,*ret,*str;int len=7,i;
cJSON *child=item->child;
depth++;out=malloc(len+depth);*out='{';
ptr=out+1;*ptr++='\n';*ptr=0;
while (child)
{
str=print_string_ptr(child->string);
if (!str) {free(out);return 0;}
ret=print_value(child,depth);
if (!ret) {free(out);return 0;} // Check for failure!
len+=strlen(ret)+strlen(str)+4+depth;
Thanks! Fixed in svn rev 9!