1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-29 13:56:47 +03:00

jsonapi: fix memory leakage during OOM error recovery.

Coverity pointed out that inc_lex_level() would leak memory
(not to mention corrupt the pstack data structure) if some
but not all of its three REALLOC's failed.  To fix, store
successfully-updated pointers back into the pstack struct
immediately.

Oversight in 0785d1b8b, so no need for back-patch.
This commit is contained in:
Tom Lane 2024-09-23 12:30:51 -04:00
parent a7e5237f26
commit 75240f65e7

View File

@ -544,19 +544,28 @@ inc_lex_level(JsonLexContext *lex)
new_prediction = REALLOC(lex->pstack->prediction,
new_stack_size * JS_MAX_PROD_LEN);
new_fnames = REALLOC(lex->pstack->fnames,
new_stack_size * sizeof(char *));
new_fnull = REALLOC(lex->pstack->fnull, new_stack_size * sizeof(bool));
#ifdef JSONAPI_USE_PQEXPBUFFER
if (!new_prediction || !new_fnames || !new_fnull)
if (!new_prediction)
return false;
#endif
lex->pstack->prediction = new_prediction;
new_fnames = REALLOC(lex->pstack->fnames,
new_stack_size * sizeof(char *));
#ifdef JSONAPI_USE_PQEXPBUFFER
if (!new_fnames)
return false;
#endif
lex->pstack->fnames = new_fnames;
new_fnull = REALLOC(lex->pstack->fnull, new_stack_size * sizeof(bool));
#ifdef JSONAPI_USE_PQEXPBUFFER
if (!new_fnull)
return false;
#endif
lex->pstack->fnull = new_fnull;
lex->pstack->stack_size = new_stack_size;
lex->pstack->prediction = new_prediction;
lex->pstack->fnames = new_fnames;
lex->pstack->fnull = new_fnull;
}
lex->lex_level += 1;