From 977d50d254b0dd1e7ba821d05345980ede33759d Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Fri, 30 Sep 2011 03:16:37 +0000 Subject: Added an option for using malloc in the pool alloc. Helps with tracking down memory leaks with valgrind. Fixed a couple leaks. --- autogen.sh | 2 +- colm/pool.c | 10 ++++++++++ colm/tree.c | 7 ------- configure.in | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/autogen.sh b/autogen.sh index a9444153..be06eec4 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,7 +1,7 @@ #!/bin/bash # -libtoolize --copy --force +#libtoolize --copy --force aclocal autoheader automake --foreign --add-missing diff --git a/colm/pool.c b/colm/pool.c index a4f7d681..022f134f 100644 --- a/colm/pool.c +++ b/colm/pool.c @@ -38,6 +38,11 @@ void *poolAllocAllocate( PoolAlloc *poolAlloc ) { debug( REALM_POOL, "pool allocation\n" ); +#ifdef POOL_MALLOC + void *res = malloc( poolAlloc->sizeofT ); + memset( res, 0, poolAlloc->sizeofT ); + return res; +#else //#ifdef COLM_LOG_BYTECODE //cerr << "allocating in: " << __PRETTY_FUNCTION__ << endl; //#endif @@ -65,6 +70,7 @@ void *poolAllocAllocate( PoolAlloc *poolAlloc ) } memset( newEl, 0, poolAlloc->sizeofT ); return newEl; +#endif } void poolAllocFree( PoolAlloc *poolAlloc, void *el ) @@ -78,9 +84,13 @@ void poolAllocFree( PoolAlloc *poolAlloc, void *el ) memset( el, 0xcc, sizeof(T) ); #endif +#ifdef POOL_MALLOC + free( el ); +#else PoolItem *pi = (PoolItem*) el; pi->next = poolAlloc->pool; poolAlloc->pool = pi; +#endif } void poolAllocClear( PoolAlloc *poolAlloc ) diff --git a/colm/tree.c b/colm/tree.c index d82ad0d5..f3661f2b 100644 --- a/colm/tree.c +++ b/colm/tree.c @@ -272,7 +272,6 @@ Tree *constructReplacementTree( Tree **bindings, Program *prg, long pat ) leftIgnore = ilAllocate( prg ); leftIgnore->id = LEL_ID_IGNORE_LIST; - leftIgnore->refs = 1; leftIgnore->child = ignore; leftIgnore->generation = prg->nextIlGen++; @@ -291,7 +290,6 @@ Tree *constructReplacementTree( Tree **bindings, Program *prg, long pat ) leftIgnore = ilAllocate( prg ); leftIgnore->id = LEL_ID_IGNORE_LIST; - leftIgnore->refs = 1; leftIgnore->child = 0; leftIgnore->generation = prg->nextIlGen++; leftIgnore->cmd = IL_CMD_GO_LEFT; @@ -316,7 +314,6 @@ Tree *constructReplacementTree( Tree **bindings, Program *prg, long pat ) IgnoreList *rightIgnore = ilAllocate( prg ); rightIgnore->id = LEL_ID_IGNORE_LIST; - rightIgnore->refs = 1; rightIgnore->child = 0; rightIgnore->generation = prg->nextIlGen++; rightIgnore->cmd = IL_CMD_GO_RIGHT; @@ -1133,7 +1130,6 @@ void setUiterCur( Program *prg, UserIter *uiter, Tree *tree ) IgnoreList *leftIgnore = ilAllocate( prg ); leftIgnore->id = LEL_ID_IGNORE_LIST; - leftIgnore->refs = 1; leftIgnore->child = 0; leftIgnore->generation = prg->nextIlGen++; leftIgnore->cmd = IL_CMD_GO_LEFT; @@ -1156,7 +1152,6 @@ void setUiterCur( Program *prg, UserIter *uiter, Tree *tree ) IgnoreList *rightIgnore = ilAllocate( prg ); rightIgnore->id = LEL_ID_IGNORE_LIST; - rightIgnore->refs = 1; rightIgnore->child = 0; rightIgnore->generation = prg->nextIlGen++; rightIgnore->cmd = IL_CMD_GO_RIGHT; @@ -1186,7 +1181,6 @@ void setTriterCur( Program *prg, TreeIter *iter, Tree *tree ) IgnoreList *leftIgnore = ilAllocate( prg ); leftIgnore->id = LEL_ID_IGNORE_LIST; - leftIgnore->refs = 1; leftIgnore->child = 0; leftIgnore->generation = prg->nextIlGen++; leftIgnore->cmd = IL_CMD_GO_LEFT; @@ -1209,7 +1203,6 @@ void setTriterCur( Program *prg, TreeIter *iter, Tree *tree ) IgnoreList *rightIgnore = ilAllocate( prg ); rightIgnore->id = LEL_ID_IGNORE_LIST; - rightIgnore->refs = 1; rightIgnore->child = 0; rightIgnore->generation = prg->nextIlGen++; rightIgnore->cmd = IL_CMD_GO_RIGHT; diff --git a/configure.in b/configure.in index 983599c1..78f39515 100644 --- a/configure.in +++ b/configure.in @@ -61,6 +61,9 @@ AC_LANG_CPLUSPLUS dnl Check for definition of MAKE. AC_PROG_MAKE_SET +AC_ARG_ENABLE(pool-malloc, "allocate pool objects with malloc", + AC_DEFINE([POOL_MALLOC], [1], [allocate pool objects with malloc])) + # Logging features # AC_ARG_ENABLE(log, "turn on logging", AC_DEFINE(COLM_LOG)) # AC_ARG_ENABLE(log-bytecode, "turns on bytecode logging", AC_DEFINE(COLM_LOG_BYTECODE)) -- cgit v1.2.1