Skip to content

Commit 7d93d62

Browse files
authored
Bug Fix: 析构时报错
1 parent 4b797e9 commit 7d93d62

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

core/JsonArray.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ void JsonArrayPushBack(struct JsonArray* arr, struct JsonVal* val) {
4949

5050
void destoryJsonArray(struct JsonArray* arr) {
5151
if (arr == NULL) return;
52-
for (size_t i = 0; i < arr->length; i++)
53-
if(arr->arr + i != NULL)
54-
free(arr->arr + i); // Avoid double free
52+
if(arr->arr != NULL) free(arr->arr); // Avoid double free
5553
free(arr);
5654
}

core/JsonObject.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ void JsonObjInsert(
2424
}
2525

2626
void destoryJsonObj(struct JsonObj* obj) {
27-
for (int i = 0; i < obj->size; i++) {
28-
destoryJsonString(obj->key + i);
29-
destoryJsonVal(obj->value + i);
30-
}
27+
if(obj->key != NULL) destoryJsonString(obj->key);
28+
if(obj->val != NULL) destoryJsonVal(obj->value);
29+
3130
}

0 commit comments

Comments
 (0)