Add some error checking for stale DOH object use
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13520 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2d24ca37d1
commit
cdfa81e572
1 changed files with 17 additions and 1 deletions
|
|
@ -20,6 +20,11 @@ char cvsroot_memory_c[] = "$Id$";
|
||||||
#define DOH_POOL_SIZE 16384
|
#define DOH_POOL_SIZE 16384
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */
|
||||||
|
/*
|
||||||
|
#define DEBUG_MEMORY_POOLS
|
||||||
|
*/
|
||||||
|
|
||||||
static int PoolSize = DOH_POOL_SIZE;
|
static int PoolSize = DOH_POOL_SIZE;
|
||||||
|
|
||||||
DOH *DohNone = 0; /* The DOH None object */
|
DOH *DohNone = 0; /* The DOH None object */
|
||||||
|
|
@ -81,8 +86,14 @@ int DohCheck(const DOH *ptr) {
|
||||||
register Pool *p = Pools;
|
register Pool *p = Pools;
|
||||||
register char *cptr = (char *) ptr;
|
register char *cptr = (char *) ptr;
|
||||||
while (p) {
|
while (p) {
|
||||||
if ((cptr >= p->pbeg) && (cptr < p->pend))
|
if ((cptr >= p->pbeg) && (cptr < p->pend)) {
|
||||||
|
#ifdef DEBUG_MEMORY_POOLS
|
||||||
|
DohBase *b = (DohBase *) ptr;
|
||||||
|
int already_deleted = b->type == 0;
|
||||||
|
assert(!already_deleted);
|
||||||
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
pptr = (char *) p->ptr;
|
pptr = (char *) p->ptr;
|
||||||
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
|
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
|
||||||
|
|
@ -110,16 +121,20 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) {
|
||||||
DohBase *obj;
|
DohBase *obj;
|
||||||
if (!pools_initialized)
|
if (!pools_initialized)
|
||||||
InitPools();
|
InitPools();
|
||||||
|
#ifndef DEBUG_MEMORY_POOLS
|
||||||
if (FreeList) {
|
if (FreeList) {
|
||||||
obj = FreeList;
|
obj = FreeList;
|
||||||
FreeList = (DohBase *) obj->data;
|
FreeList = (DohBase *) obj->data;
|
||||||
} else {
|
} else {
|
||||||
|
#endif
|
||||||
while (Pools->current == Pools->len) {
|
while (Pools->current == Pools->len) {
|
||||||
CreatePool();
|
CreatePool();
|
||||||
}
|
}
|
||||||
obj = Pools->ptr + Pools->current;
|
obj = Pools->ptr + Pools->current;
|
||||||
++Pools->current;
|
++Pools->current;
|
||||||
|
#ifndef DEBUG_MEMORY_POOLS
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
obj->type = type;
|
obj->type = type;
|
||||||
obj->data = data;
|
obj->data = data;
|
||||||
obj->meta = 0;
|
obj->meta = 0;
|
||||||
|
|
@ -144,6 +159,7 @@ void DohObjFree(DOH *ptr) {
|
||||||
b->data = (void *) FreeList;
|
b->data = (void *) FreeList;
|
||||||
b->meta = 0;
|
b->meta = 0;
|
||||||
b->type = 0;
|
b->type = 0;
|
||||||
|
b->refcount = 0;
|
||||||
FreeList = b;
|
FreeList = b;
|
||||||
if (meta) {
|
if (meta) {
|
||||||
Delete(meta);
|
Delete(meta);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue