Skip to content

Commit 0eca326

Browse files
authored
Merge pull request from GHSA-q4m7-9pcm-fpxh
Clear `alc` in the `doc_free()` function to prevent users from mistakenly freeing the same doc multiple times.
2 parents 1f2e748 + c8cb62e commit 0eca326

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/yyjson.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) {
14071407
void yyjson_mut_doc_free(yyjson_mut_doc *doc) {
14081408
if (doc) {
14091409
yyjson_alc alc = doc->alc;
1410+
memset(&doc->alc, 0, sizeof(alc));
14101411
unsafe_yyjson_str_pool_release(&doc->str_pool, &alc);
14111412
unsafe_yyjson_val_pool_release(&doc->val_pool, &alc);
14121413
alc.free(alc.ctx, doc);

src/yyjson.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4833,6 +4833,7 @@ yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) {
48334833
yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc) {
48344834
if (doc) {
48354835
yyjson_alc alc = doc->alc;
4836+
memset(&doc->alc, 0, sizeof(alc));
48364837
if (doc->str_pool) alc.free(alc.ctx, doc->str_pool);
48374838
alc.free(alc.ctx, doc);
48384839
}

0 commit comments

Comments
 (0)