Make valgrind know about eina mempools.
authorrfonseca <rfonseca@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
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)
commitd09a8cf5c1fd2615bd256aa69d7fb3226d7d119d
treeeda3a767516646c93d8a68baa80249569cc6c952
parent85dc7e9e4d1a8eef18075ef91e61235215a40658
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: svn+ssh://svn.enlightenment.org/var/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