@@ -176,9 +176,20 @@ read_stream_get_block(ReadStream *stream, void *per_buffer_data)
176
176
if (blocknum != InvalidBlockNumber )
177
177
stream -> buffered_blocknum = InvalidBlockNumber ;
178
178
else
179
+ {
180
+ /*
181
+ * Tell Valgrind that the per-buffer data is undefined. That replaces
182
+ * the "noaccess" state that was set when the consumer moved past this
183
+ * entry last time around the queue, and should also catch callbacks
184
+ * that fail to initialize data that the buffer consumer later
185
+ * accesses. On the first go around, it is undefined already.
186
+ */
187
+ VALGRIND_MAKE_MEM_UNDEFINED (per_buffer_data ,
188
+ stream -> per_buffer_data_size );
179
189
blocknum = stream -> callback (stream ,
180
190
stream -> callback_private_data ,
181
191
per_buffer_data );
192
+ }
182
193
183
194
return blocknum ;
184
195
}
@@ -687,8 +698,11 @@ read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
687
698
}
688
699
689
700
#ifdef CLOBBER_FREED_MEMORY
690
- /* Clobber old buffer and per-buffer data for debugging purposes. */
701
+ /* Clobber old buffer for debugging purposes. */
691
702
stream -> buffers [oldest_buffer_index ] = InvalidBuffer ;
703
+ #endif
704
+
705
+ #if defined(CLOBBER_FREED_MEMORY ) || defined(USE_VALGRIND )
692
706
693
707
/*
694
708
* The caller will get access to the per-buffer data, until the next call.
@@ -697,11 +711,23 @@ read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
697
711
* that is holding a dangling pointer to it.
698
712
*/
699
713
if (stream -> per_buffer_data )
700
- wipe_mem (get_per_buffer_data (stream ,
701
- oldest_buffer_index == 0 ?
702
- stream -> queue_size - 1 :
703
- oldest_buffer_index - 1 ),
704
- stream -> per_buffer_data_size );
714
+ {
715
+ void * per_buffer_data ;
716
+
717
+ per_buffer_data = get_per_buffer_data (stream ,
718
+ oldest_buffer_index == 0 ?
719
+ stream -> queue_size - 1 :
720
+ oldest_buffer_index - 1 );
721
+
722
+ #if defined(CLOBBER_FREED_MEMORY )
723
+ /* This also tells Valgrind the memory is "noaccess". */
724
+ wipe_mem (per_buffer_data , stream -> per_buffer_data_size );
725
+ #elif defined(USE_VALGRIND )
726
+ /* Tell it ourselves. */
727
+ VALGRIND_MAKE_MEM_NOACCESS (per_buffer_data ,
728
+ stream -> per_buffer_data_size );
729
+ #endif
730
+ }
705
731
#endif
706
732
707
733
/* Pin transferred to caller. */
0 commit comments