pgsql: Avoid leakage of zero-length arrays in partition_bounds_copy().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid leakage of zero-length arrays in partition_bounds_copy().
Date: 2025-08-03 02:00:50
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid leakage of zero-length arrays in partition_bounds_copy().

If ndatums is zero, the code would allocate zero-length boundKinds
and boundDatums chunks, which would have nothing pointing to them,
leading to Valgrind complaints. Rearrange the code to avoid the
useless pallocs, and also to not bother computing byval/typlen when
they aren't used.

I'm unsure why I didn't see this in my Valgrind testing back in May.
This code hasn't changed since then, but maybe we added a regression
test that reaches this edge case. Or possibly I just failed to
notice the reports, which do say "0 bytes lost".

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4fbfdde58e4cd091f88737dffa241b08c23d8829

Modified Files
--------------
src/backend/partitioning/partbounds.c | 57 ++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 28 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-08-03 17:01:59 pgsql: Take a little more care in set_backtrace().
Previous Message Fujii Masao 2025-08-03 01:55:01 pgsql: Fix assertion failure in pgbench when handling multiple pipeline