pgsql: Fix valgrind's "unaddressable bytes" whining about BRIN code.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix valgrind's "unaddressable bytes" whining about BRIN code.
Date: 2015-05-26 01:56:22
Message-ID: E1Yx46Q-0004fM-Pp@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix valgrind's "unaddressable bytes" whining about BRIN code.

brin_form_tuple calculated an exact tuple size, then palloc'd and
filled just that much. Later, brin_doinsert or brin_doupdate would
MAXALIGN the tuple size and tell PageAddItem that that was the size
of the tuple to insert. If the original tuple size wasn't a multiple
of MAXALIGN, the net result would be that PageAddItem would memcpy
a few more bytes than the palloc request had been for.

AFAICS, this is totally harmless in the real world: the error is a
read overrun not a write overrun, and palloc would certainly have
rounded the request up to a MAXALIGN multiple internally, so there's
no chance of the memcpy fetching off the end of memory. Valgrind,
however, is picky to the byte level not the MAXALIGN level.

Fix it by pushing the MAXALIGN step back to brin_form_tuple. (The other
possible source of tuples in this code, brin_form_placeholder_tuple,
was already producing a MAXALIGN'd result.)

In passing, be a bit more paranoid about internal allocations in
brin_form_tuple.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/79f2b5d583e2e2a7ccd13e31d0e20a900c8f2f61

Modified Files
--------------
src/backend/access/brin/brin_pageops.c | 4 ++--
src/backend/access/brin/brin_tuple.c | 15 +++++++++++----
2 files changed, 13 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Stephen Frost 2015-05-26 13:08:00 Re: [COMMITTERS] pgsql: Row-Level Security Policies (RLS)
Previous Message Bruce Momjian 2015-05-25 20:54:31 pgsql: pgindent: document location of "all" typedef lists