buffer, defaultmem: add option to poison memory before freeing it
authorTim-Philipp Müller <tim@centricular.net>
Sat, 4 Aug 2012 12:37:32 +0000 (13:37 +0100)
committerTim-Philipp Müller <tim@centricular.net>
Sat, 4 Aug 2012 12:37:32 +0000 (13:37 +0100)
Might be useful to track down certain bugs.

gst/gstallocator.c
gst/gstbuffer.c

index 30b73d7..fea534b 100644 (file)
@@ -517,11 +517,19 @@ static void
 default_free (GstAllocator * allocator, GstMemory * mem)
 {
   GstMemoryDefault *dmem = (GstMemoryDefault *) mem;
+  gsize slice_size;
 
   if (dmem->notify)
     dmem->notify (dmem->user_data);
 
-  g_slice_free1 (dmem->slice_size, mem);
+  slice_size = dmem->slice_size;
+
+#ifdef USE_POISONING
+  /* just poison the structs, not all the data */
+  memset (mem, 0xff, sizeof (GstMemoryDefault));
+#endif
+
+  g_slice_free1 (slice_size, mem);
 }
 
 static void
index 4269310..385dde6 100644 (file)
@@ -532,10 +532,14 @@ _gst_buffer_free (GstBuffer * buffer)
   }
 
   /* we set msize to 0 when the buffer is part of the memory block */
-  if (msize)
+  if (msize) {
+#ifdef USE_POISONING
+    memset (buffer, 0xff, msize);
+#endif
     g_slice_free1 (msize, buffer);
-  else
+  } else {
     gst_memory_unref (GST_BUFFER_BUFMEM (buffer));
+  }
 }
 
 static void