relcache: Avoid memory leak on tables with no CHECK constraints

Álvaro Herrera <alvherre@kurilemu.de>

Commit: dc9a2d54fd2571c21c074103cc8ddd93e840b985
Author: Álvaro Herrera <alvherre@kurilemu.de>
Date: 2025-05-11T13:22:12Z
Releases: 18.0
relcache: Avoid memory leak on tables with no CHECK constraints

As complained about by Valgrind, in commit a379061a22a8 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

Files

PathChange+/−
src/backend/utils/cache/relcache.c modified +7 −4

Discussion