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

Commit2a8a006

Browse files
committed
Fix explicit valgrind interaction in read_stream.c.
By calling wipe_mem() on per-buffer data memory that has been released,we are also telling Valgrind that the memory is "noaccess". We need toset it to "undefined" before giving it to the registered callback tofill in, when a slot is reused.As discovered by build farm animal skink when the VACUUM streamificationpatches landed (the first users of per-buffer data).Pushing to master only for now, to clear the error on skink. It's alsopossible that external code might discover the per-buffer data featurein v17, and reasonable to expect Valgrind not to produce spuriousmemcheck reports, but the back-patch is deferred until after theimminent minor release is out of the way.Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Tested-by: Melanie Plageman <melanieplageman@gmail.com>Discussion:https://postgr.es/m/CA%2BhUKG%2Bg6aXpi2FEHqeLOzE%2BxYw%3DOV%2B-N5jhOEnnV%2BF0USM9xA%40mail.gmail.com
1 parentefdadeb commit2a8a006

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

‎src/backend/storage/aio/read_stream.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,20 @@ read_stream_get_block(ReadStream *stream, void *per_buffer_data)
193193
if (blocknum!=InvalidBlockNumber)
194194
stream->buffered_blocknum=InvalidBlockNumber;
195195
else
196+
{
197+
/*
198+
* Tell Valgrind that the per-buffer data is undefined. That replaces
199+
* the "noaccess" state that was set when the consumer moved past this
200+
* entry last time around the queue, and should also catch callbacks
201+
* that fail to initialize data that the buffer consumer later
202+
* accesses. On the first go around, it is undefined already.
203+
*/
204+
VALGRIND_MAKE_MEM_UNDEFINED(per_buffer_data,
205+
stream->per_buffer_data_size);
196206
blocknum=stream->callback(stream,
197207
stream->callback_private_data,
198208
per_buffer_data);
209+
}
199210

200211
returnblocknum;
201212
}
@@ -752,8 +763,11 @@ read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
752763
}
753764

754765
#ifdefCLOBBER_FREED_MEMORY
755-
/* Clobber old bufferand per-buffer datafor debugging purposes. */
766+
/* Clobber old buffer for debugging purposes. */
756767
stream->buffers[oldest_buffer_index]=InvalidBuffer;
768+
#endif
769+
770+
#if defined(CLOBBER_FREED_MEMORY)|| defined(USE_VALGRIND)
757771

758772
/*
759773
* The caller will get access to the per-buffer data, until the next call.
@@ -762,11 +776,23 @@ read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
762776
* that is holding a dangling pointer to it.
763777
*/
764778
if (stream->per_buffer_data)
765-
wipe_mem(get_per_buffer_data(stream,
766-
oldest_buffer_index==0 ?
767-
stream->queue_size-1 :
768-
oldest_buffer_index-1),
769-
stream->per_buffer_data_size);
779+
{
780+
void*per_buffer_data;
781+
782+
per_buffer_data=get_per_buffer_data(stream,
783+
oldest_buffer_index==0 ?
784+
stream->queue_size-1 :
785+
oldest_buffer_index-1);
786+
787+
#if defined(CLOBBER_FREED_MEMORY)
788+
/* This also tells Valgrind the memory is "noaccess". */
789+
wipe_mem(per_buffer_data,stream->per_buffer_data_size);
790+
#elif defined(USE_VALGRIND)
791+
/* Tell it ourselves. */
792+
VALGRIND_MAKE_MEM_NO_ACCESS(per_buffer_data,
793+
stream->per_buffer_data_size);
794+
#endif
795+
}
770796
#endif
771797

772798
/* Pin transferred to caller. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp