mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Don't leak the non-GeoJSON objects in the JSON parse tree
This commit is contained in:
+10
-4
@@ -86,6 +86,7 @@ json_pull *json_begin_string(char *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void json_end(json_pull *p) {
|
void json_end(json_pull *p) {
|
||||||
|
json_free(p->root);
|
||||||
free(p->buffer);
|
free(p->buffer);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
@@ -102,7 +103,7 @@ static inline int read_wrap(json_pull *j) {
|
|||||||
|
|
||||||
#define SIZE_FOR(i, size) ((size_t)((((i) + 31) & ~31) * size))
|
#define SIZE_FOR(i, size) ((size_t)((((i) + 31) & ~31) * size))
|
||||||
|
|
||||||
static json_object *fabricate_object(json_object *parent, json_type type) {
|
static json_object *fabricate_object(json_pull *jp, json_object *parent, json_type type) {
|
||||||
json_object *o = malloc(sizeof(struct json_object));
|
json_object *o = malloc(sizeof(struct json_object));
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
perror("Out of memory");
|
perror("Out of memory");
|
||||||
@@ -114,12 +115,13 @@ static json_object *fabricate_object(json_object *parent, json_type type) {
|
|||||||
o->keys = NULL;
|
o->keys = NULL;
|
||||||
o->values = NULL;
|
o->values = NULL;
|
||||||
o->length = 0;
|
o->length = 0;
|
||||||
|
o->parser = jp;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
static json_object *add_object(json_pull *j, json_type type) {
|
static json_object *add_object(json_pull *j, json_type type) {
|
||||||
json_object *c = j->container;
|
json_object *c = j->container;
|
||||||
json_object *o = fabricate_object(c, type);
|
json_object *o = fabricate_object(j, c, type);
|
||||||
|
|
||||||
if (c != NULL) {
|
if (c != NULL) {
|
||||||
if (c->type == JSON_ARRAY) {
|
if (c->type == JSON_ARRAY) {
|
||||||
@@ -662,11 +664,11 @@ void json_disconnect(json_object *o) {
|
|||||||
|
|
||||||
for (i = 0; i < o->parent->length; i++) {
|
for (i = 0; i < o->parent->length; i++) {
|
||||||
if (o->parent->keys[i] == o) {
|
if (o->parent->keys[i] == o) {
|
||||||
o->parent->keys[i] = fabricate_object(o->parent, JSON_NULL);
|
o->parent->keys[i] = fabricate_object(o->parser, o->parent, JSON_NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (o->parent->values[i] == o) {
|
if (o->parent->values[i] == o) {
|
||||||
o->parent->values[i] = fabricate_object(o->parent, JSON_NULL);
|
o->parent->values[i] = fabricate_object(o->parser, o->parent, JSON_NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -686,6 +688,10 @@ void json_disconnect(json_object *o) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (o->parser != NULL && o->parser->root == o) {
|
||||||
|
o->parser->root = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
o->parent = NULL;
|
o->parent = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ typedef enum json_type {
|
|||||||
typedef struct json_object {
|
typedef struct json_object {
|
||||||
json_type type;
|
json_type type;
|
||||||
struct json_object *parent;
|
struct json_object *parent;
|
||||||
|
struct json_pull *parser;
|
||||||
|
|
||||||
char *string;
|
char *string;
|
||||||
double number;
|
double number;
|
||||||
|
|||||||
Reference in New Issue
Block a user