Make valgrind know about eina mempools.
authorrfonseca <rfonseca>
Thu, 14 Oct 2010 15:18:15 +0000 (15:18 +0000)
committerrfonseca <rfonseca@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 14 Oct 2010 15:18:15 +0000 (15:18 +0000)
commitbaf3f0284180520c7cb6b94b4134ef99b8d244e7
treeeda3a767516646c93d8a68baa80249569cc6c952
parent7c0d4aa44b07ede350bbf1c3f61219e023665a59
Make valgrind know about eina mempools.

Because mempools generally allocate a big memory area and distribute chunks of
that area to the users, valgrind can not know about logical invalid access. By
using some valgrind macros we can tell valgrind about mempools and which area
can be accessed or not.

To start with I have just done valgrind integration on chained mempool but soon
it will be done for one_big too.

The code below is an example on which valgrind wouldn't complain without this
patch:

@code
#include <Eina.h>

int
main(int argc, char *argv[])
{
    int i, *pool[4];
    Eina_Mempool *mp;

    eina_init();
    mp = eina_mempool_add("chained_mempool", "test", NULL, sizeof(int), 4);

    for (i = 0; i < 4; i++) {
        pool[i] = eina_mempool_malloc(mp, sizeof(int));
        *pool[i] = i;
    }

    printf("Valid mp pointer: pool[0] = %d\n", *pool[0]);
    eina_mempool_free(mp, pool[0]);
    printf("Freed mp pointer: pool[0] = %d\n", *pool[0]);

    for (i = 1; i < 4; i++)
        eina_mempool_free(mp, pool[i]);

    eina_mempool_del(mp);
    eina_shutdown();

    return 0;
}
@endcode

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@53405 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33
configure.ac
src/modules/mp/chained_pool/Makefile.am
src/modules/mp/chained_pool/eina_chained_mempool.c