• Tom Lane's avatar
    Fix valgrind's "unaddressable bytes" whining about BRIN code. · 79f2b5d5
    Tom Lane authored
    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.
    79f2b5d5
brin_pageops.c 17.6 KB