mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
relcache: Avoid memory leak on tables with no CHECK constraints
As complained about by Valgrind, in commit a379061a22
I failed to
realize that I was causing rd_att->constr->check to become allocated
when no CHECK constraints exist; previously it'd remain NULL. (This was
my bug, not the mentioned commit author's). Fix by making the
allocation conditional, and set ->check to NULL if unallocated.
Reported-by: Yasir <yasir.hussain.shah@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/202505082025.57ijx3qrbx7u@alvherre.pgsql
This commit is contained in:
11
src/backend/utils/cache/relcache.c
vendored
11
src/backend/utils/cache/relcache.c
vendored
@ -4598,10 +4598,13 @@ CheckNNConstraintFetch(Relation relation)
|
|||||||
HeapTuple htup;
|
HeapTuple htup;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
/* Allocate array with room for as many entries as expected */
|
/* Allocate array with room for as many entries as expected, if needed */
|
||||||
check = (ConstrCheck *)
|
if (ncheck > 0)
|
||||||
MemoryContextAllocZero(CacheMemoryContext,
|
check = (ConstrCheck *)
|
||||||
ncheck * sizeof(ConstrCheck));
|
MemoryContextAllocZero(CacheMemoryContext,
|
||||||
|
ncheck * sizeof(ConstrCheck));
|
||||||
|
else
|
||||||
|
check = NULL;
|
||||||
|
|
||||||
/* Search pg_constraint for relevant entries */
|
/* Search pg_constraint for relevant entries */
|
||||||
ScanKeyInit(&skey[0],
|
ScanKeyInit(&skey[0],
|
||||||
|
Reference in New Issue
Block a user