Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc9a2d5

Browse files
author
Álvaro Herrera
committed
relcache: Avoid memory leak on tables with no CHECK constraints
As complained about by Valgrind, in commit a379061 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 <[email protected]> Reviewed-by: Tom Lane <[email protected]> Discussion: https://postgr.es/m/[email protected]
1 parent 7b2ad43 commit dc9a2d5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/backend/utils/cache/relcache.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -4598,10 +4598,13 @@ CheckNNConstraintFetch(Relation relation)
45984598
HeapTuple htup;
45994599
int found = 0;
46004600

4601-
/* Allocate array with room for as many entries as expected */
4602-
check = (ConstrCheck *)
4603-
MemoryContextAllocZero(CacheMemoryContext,
4604-
ncheck * sizeof(ConstrCheck));
4601+
/* Allocate array with room for as many entries as expected, if needed */
4602+
if (ncheck > 0)
4603+
check = (ConstrCheck *)
4604+
MemoryContextAllocZero(CacheMemoryContext,
4605+
ncheck * sizeof(ConstrCheck));
4606+
else
4607+
check = NULL;
46054608

46064609
/* Search pg_constraint for relevant entries */
46074610
ScanKeyInit(&skey[0],

0 commit comments

Comments
 (0)