Skip to content

Commit

Permalink
Merge pull request from GHSA-q4m7-9pcm-fpxh
Browse files Browse the repository at this point in the history
Clear `alc` in the `doc_free()` function to prevent users from mistakenly freeing the same doc multiple times.
  • Loading branch information
ibireme authored Feb 6, 2024
2 parents 1f2e748 + c8cb62e commit 0eca326
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/yyjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) {
void yyjson_mut_doc_free(yyjson_mut_doc *doc) {
if (doc) {
yyjson_alc alc = doc->alc;
memset(&doc->alc, 0, sizeof(alc));
unsafe_yyjson_str_pool_release(&doc->str_pool, &alc);
unsafe_yyjson_val_pool_release(&doc->val_pool, &alc);
alc.free(alc.ctx, doc);
Expand Down
1 change: 1 addition & 0 deletions src/yyjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -4833,6 +4833,7 @@ yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) {
yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc) {
if (doc) {
yyjson_alc alc = doc->alc;
memset(&doc->alc, 0, sizeof(alc));
if (doc->str_pool) alc.free(alc.ctx, doc->str_pool);
alc.free(alc.ctx, doc);
}
Expand Down

0 comments on commit 0eca326

Please sign in to comment.