char* psz_childdelim = NULL;
char* psz_nametag = NULL;
char* psz_response = strdup( "" );
+ char *psz_tmp;
int i_success = 0;
int i;
vlm_message_t *aw_child, **paw_child;
/* Append name of child node, if not in a list */
if( !i_list )
{
- i_success = asprintf( &psz_response, "%s\"%s\": ",
+ i_success = asprintf( &psz_tmp, "%s\"%s\": ",
psz_response, aw_child->psz_name );
if( i_success == -1 ) break;
+ free( psz_response );
+ psz_response = psz_tmp;
}
/* If child node has children, */
strcmp( aw_child->psz_name, "inputs" ) == 0 ||
strcmp( aw_child->psz_name, "options" ) == 0 )
{
- i_success = asprintf( &psz_response, "%s[%s%s%s]%c%s",
- psz_response, psz_childdelim,
- recurse_answer( aw_child,
- psz_childdelim, 1 ),
+ char *psz_recurse = recurse_answer( aw_child, psz_childdelim, 1 ),
+ i_success = asprintf( &psz_tmp, "%s[%s%s%s]%c%s",
+ psz_response, psz_childdelim, psz_recurse,
psz_delim, c_comma, psz_delim );
+ free( psz_recurse );
if( i_success == -1 ) break;
+ free( psz_response );
+ psz_response = psz_tmp;
}
/* Not a list, so format the child as a JSON object and
* recurse through the child's children
*/
else
{
- i_success = asprintf( &psz_response, "%s{%s%s%s%s}%c%s",
+ char *psz_recurse = recurse_answer( aw_child, psz_childdelim, 0 ),
+ i_success = asprintf( &psz_tmp, "%s{%s%s%s%s}%c%s",
psz_response, psz_childdelim, psz_nametag,
- recurse_answer( aw_child,
- psz_childdelim, 0 ),
- psz_delim, c_comma, psz_delim );
+ psz_recurse, psz_delim, c_comma, psz_delim );
+ free( psz_recurse );
if( i_success == -1 ) break;
+ free( psz_response );
+ psz_response = psz_tmp;
}
}
/* Otherwise - when no children are present - the node is a
if( aw_child->psz_value == NULL
|| strcmp( aw_child->psz_value, "(null)" ) == 0 )
{
- i_success = asprintf( &psz_response, "%snull%c%s",
+ i_success = asprintf( &psz_tmp, "%snull%c%s",
psz_response, c_comma, psz_delim );
- if( i_success == -1 )
- break;
+ if( i_success == -1 ) break;
+ free( psz_response );
+ psz_response = psz_tmp;
}
/* Otherwise print the value in quotation marks */
else
{
- i_success = asprintf( &psz_response, "%s\"%s\"%c%s",
+ i_success = asprintf( &psz_tmp, "%s\"%s\"%c%s",
psz_response, aw_child->psz_value,
c_comma, psz_delim );
if( i_success == -1 ) break;
+ free( psz_response );
+ psz_response = psz_tmp;
}
}
/* getting next child */
psz_delimiter = "\n";
i_list = 1;
}
- if( asprintf( &psz_response, psz_fmt,
- recurse_answer( answer, psz_delimiter, i_list ) ) == -1 )
+ char *psz_tmp = recurse_answer( answer, psz_delimiter, i_list );
+ if( asprintf( &psz_response, psz_fmt, psz_tmp ) == -1 )
{
libvlc_printerr( "Out of memory" );
psz_response = NULL;
}
+ free( psz_tmp );
}
free( psz_message );
return( psz_response );