Ejemplo n.º 1
0
void json_release(struct JSON *json)
{
	struct JSON *tmp;
	if(json==NULL){
		return;
	}
	else{
		if(json->parent==NULL){
			free(json->position);
			json->position = NULL;
		}
		while(json!=NULL){
			tmp = json->next;
			if(json->keyword!=NULL){
				free(json->keyword);
			}
			if(strcmp(json->type,"object")==0||strcmp(json->type,"array")==0){
				json_release(json->data.object);
			}
			else if(strcmp(json->type,"string")==0){
				free(json->data.string);
			}
			free(json);
			json = tmp;
		}
	}
}
Ejemplo n.º 2
0
struct JSON *json_parse(char *string)
{
	struct JSON *root;
	int ret = 0;
	int offset = 0; 
	char *msg = "no error.";
	char *tmp;
	int line, c;
	int len = strlen(string);
	char *str = NULL;

	if(string==NULL){
		return NULL;
	}
	str = (char *)malloc(len + 2);
	if(str==NULL){
		return NULL;
	}
	memcpy(str, string, len+1);

	root = alloc_node();
	if(root==NULL){
		return NULL;
	}
	ret = json_parse_all(str, root, &offset, &msg);
	if(ret==0){
		return root;
	}
	else{
		offset_to_line(str, offset, &line, &c);
		printf("error at line:%d character:%d, %s\n", line, c, msg);
		tmp = str + offset;
		while(*tmp!='\0' && *tmp!='\n'){
			tmp++;
		}	
		*tmp = '\0';
		printf("%s\n", str + offset - (c - 1));
		printf("%*c\n", c, '^');
		json_release(root);
		return NULL;
	}
}
Ejemplo n.º 3
0
void core_release(int report_leaks)
{
    sock_release();

	timer_releasemgr();

    fio_releasemgr();

    json_release();

    err_release();

    log_release();

    /* dump memory leaks before releasing memory manager and log
     * because memory leak report dumps leakage data to logger */
    if (report_leaks)
        mem_reportleaks();
    
    mem_release();
}