Error check things
This commit is contained in:
@@ -24,17 +24,24 @@ int total = 0; /* total dynamic memory bytes */
|
|||||||
* Free up an item
|
* Free up an item
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define ENABLE_DEBUG
|
||||||
|
#define MAX_DEBUGPTRS 100000
|
||||||
|
|
||||||
int32_t itemcounter;
|
int32_t itemcounter;
|
||||||
THING *thingptrs[100000];
|
THING *thingptrs[MAX_DEBUGPTRS];
|
||||||
int32_t numptrs;
|
int32_t numptrs;
|
||||||
|
|
||||||
int32_t thing_find(THING *item)
|
int32_t thing_find(THING *item)
|
||||||
{
|
{
|
||||||
|
#ifdef ENABLE_DEBUG
|
||||||
int32_t i;
|
int32_t i;
|
||||||
for (i=0; i<numptrs; i++)
|
for (i=0; i<numptrs; i++)
|
||||||
if ( item == thingptrs[i] )
|
if ( item == thingptrs[i] )
|
||||||
return(i);
|
return(i);
|
||||||
return(-1);
|
return(-1);
|
||||||
|
#else
|
||||||
|
return(0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -43,7 +50,7 @@ discard(THING *item)
|
|||||||
#ifdef MASTER
|
#ifdef MASTER
|
||||||
total--;
|
total--;
|
||||||
#endif
|
#endif
|
||||||
if ( 1 )
|
#ifdef ENABLE_DEBUG
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
for (i=0; i<numptrs; i++)
|
for (i=0; i<numptrs; i++)
|
||||||
@@ -54,6 +61,7 @@ discard(THING *item)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
itemcounter--;
|
itemcounter--;
|
||||||
free((char *) item);
|
free((char *) item);
|
||||||
}
|
}
|
||||||
@@ -150,12 +158,14 @@ new_item(void)
|
|||||||
#else
|
#else
|
||||||
item = (THING *)calloc(1, sizeof *item);
|
item = (THING *)calloc(1, sizeof *item);
|
||||||
#endif
|
#endif
|
||||||
if ( 1 )
|
#ifdef ENABLE_DEBUG
|
||||||
|
if ( numptrs < MAX_DEBUGPTRS )
|
||||||
{
|
{
|
||||||
thingptrs[numptrs++] = item;
|
thingptrs[numptrs++] = item;
|
||||||
if ( (++itemcounter % 100) == 0 )
|
if ( (++itemcounter % 100) == 0 )
|
||||||
fprintf(stderr,"itemcounter.%d\n",itemcounter);
|
fprintf(stderr,"itemcounter.%d\n",itemcounter);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
item->l_next = NULL;
|
item->l_next = NULL;
|
||||||
item->l_prev = NULL;
|
item->l_prev = NULL;
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
@@ -466,7 +466,14 @@ get_item(struct rogue_state *rs,char *purpose, int type)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if ( thing_find(obj) < 0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"cant find thing.%p in list\n",obj); sleep(3);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user