|
From: John R. <jr...@bi...> - 2016-05-27 04:27:35
|
=====recently.c
#include "valgrind/valgrind.h"
#include <stdlib.h>
#include <string.h>
int main()
{
int *const m0 = malloc (1<<16);
VALGRIND_CREATE_MEMPOOL(m0, (1<<16), 0); // a new pool inside a malloc()ed block
int *const m1 = (4368/sizeof(int)) + m0; // point into the interior of the pool
VALGRIND_MEMPOOL_ALLOC(m0, m1, 16); // "allocate" a block of 16 bytes from the pool
VALGRIND_MEMPOOL_FREE(m0, m1); // free the allocated block immediately
memset(m1, 0, 16); // [error] write into the free()d block
return 0;
}
=====
==2668== Invalid write of size 8
==2668== at 0x4C2EFDF: memset (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2668== by 0x40090B: main (recently.c:13)
==2668== Address 0x51f7150 is 4,368 bytes inside a recently re-allocated block of size 65,536 alloc'd
==2668== at 0x4C28C50: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2668== by 0x4007BA: main (recently.c:7)
So valgrind is trying to say that memset is writing into a free()d block,
and that the corresponding allocation was moderately recent.
Consult "valgrind --help | grep freelist" for hints,
then refer to the documentation or the source code.
|