Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79f2b5d

Browse files
committed
Fix valgrind's "unaddressable bytes" whining about BRIN code.
brin_form_tuple calculated an exact tuple size, then palloc'd andfilled just that much. Later, brin_doinsert or brin_doupdate wouldMAXALIGN the tuple size and tell PageAddItem that that was the sizeof the tuple to insert. If the original tuple size wasn't a multipleof MAXALIGN, the net result would be that PageAddItem would memcpya few more bytes than the palloc request had been for.AFAICS, this is totally harmless in the real world: the error is aread overrun not a write overrun, and palloc would certainly haverounded the request up to a MAXALIGN multiple internally, so there'sno 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 otherpossible 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 inbrin_form_tuple.
1 parent3503003 commit79f2b5d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

‎src/backend/access/brin/brin_pageops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
5555
Buffernewbuf;
5656
boolextended= false;
5757

58-
newsz=MAXALIGN(newsz);
58+
Assert(newsz==MAXALIGN(newsz));
5959

6060
/* make sure the revmap is long enough to contain the entry we need */
6161
brinRevmapExtend(revmap,heapBlk);
@@ -273,7 +273,7 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
273273
ItemPointerDatatid;
274274
boolextended= false;
275275

276-
itemsz=MAXALIGN(itemsz);
276+
Assert(itemsz==MAXALIGN(itemsz));
277277

278278
/* Make sure the revmap is long enough to contain the entry we need */
279279
brinRevmapExtend(revmap,heapBlk);

‎src/backend/access/brin/brin_tuple.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
103103

104104
Assert(brdesc->bd_totalstored>0);
105105

106-
values=palloc(sizeof(Datum)*brdesc->bd_totalstored);
107-
nulls=palloc0(sizeof(bool)*brdesc->bd_totalstored);
108-
phony_nullbitmap=palloc(sizeof(bits8)*BITMAPLEN(brdesc->bd_totalstored));
106+
values= (Datum*)palloc(sizeof(Datum)*brdesc->bd_totalstored);
107+
nulls= (bool*)palloc0(sizeof(bool)*brdesc->bd_totalstored);
108+
phony_nullbitmap= (bits8*)
109+
palloc(sizeof(bits8)*BITMAPLEN(brdesc->bd_totalstored));
109110

110111
/*
111112
* Set up the values/nulls arrays for heap_fill_tuple
@@ -144,6 +145,9 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
144145
values[idxattno++]=tuple->bt_columns[keyno].bv_values[datumno];
145146
}
146147

148+
/* Assert we did not overrun temp arrays */
149+
Assert(idxattno <=brdesc->bd_totalstored);
150+
147151
/* compute total space needed */
148152
len=SizeOfBrinTuple;
149153
if (anynulls)
@@ -160,12 +164,15 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
160164

161165
data_len=heap_compute_data_size(brtuple_disk_tupdesc(brdesc),
162166
values,nulls);
163-
164167
len+=data_len;
165168

169+
len=MAXALIGN(len);
170+
166171
rettuple=palloc0(len);
167172
rettuple->bt_blkno=blkno;
168173
rettuple->bt_info=hoff;
174+
175+
/* Assert that hoff fits in the space available */
169176
Assert((rettuple->bt_info&BRIN_OFFSET_MASK)==hoff);
170177

171178
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp