diff options
author | Andrew Dunstan | 2024-04-09 13:07:14 +0000 |
---|---|---|
committer | Andrew Dunstan | 2024-04-12 14:32:30 +0000 |
commit | 661ab4e185784db79c194b5758555b1db3f30483 (patch) | |
tree | c5fdde1cecca9ea8440f5e8e2412741acc34d580 /src/common/jsonapi.c | |
parent | b9ecefecc7aaad117e0255b56b759f524f0f4363 (diff) |
Fix some memory leaks associated with parsing json and manifests
Coverity complained about not freeing some memory associated with
incrementally parsing backup manifests. To fix that, provide and use a new
shutdown function for the JsonManifestParseIncrementalState object, in
line with a suggestion from Tom Lane.
While analysing the problem, I noticed a buglet in freeing memory for
incremental json lexers. To fix that remove a bogus condition on
freeing the memory allocated for them.
Diffstat (limited to 'src/common/jsonapi.c')
-rw-r--r-- | src/common/jsonapi.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c index 44dbb7f7f96..9dfbc397c06 100644 --- a/src/common/jsonapi.c +++ b/src/common/jsonapi.c @@ -488,19 +488,18 @@ freeJsonLexContext(JsonLexContext *lex) if (lex->errormsg) destroyStringInfo(lex->errormsg); - if (lex->flags & JSONLEX_FREE_STRUCT) + if (lex->incremental) { - if (lex->incremental) - { - pfree(lex->inc_state->partial_token.data); - pfree(lex->inc_state); - pfree(lex->pstack->prediction); - pfree(lex->pstack->fnames); - pfree(lex->pstack->fnull); - pfree(lex->pstack); - } - pfree(lex); + pfree(lex->inc_state->partial_token.data); + pfree(lex->inc_state); + pfree(lex->pstack->prediction); + pfree(lex->pstack->fnames); + pfree(lex->pstack->fnull); + pfree(lex->pstack); } + + if (lex->flags & JSONLEX_FREE_STRUCT) + pfree(lex); } /* |