for(d = descriptor_list; d != NULL; d=d_next)
{
d_next = d->next;
// rest of code here.
}
#define CleanData(point) \
do \
if(point) \
{ \
free((void *)point); \
} \
else \
log_string("CleanData: Trying to free Null point!"); \
point = NULL; \
while(0);
#define CleanData(point) \
do \
{ \
if(point) \
{ \
if(typeid(point) == typeid(char *) || typeid(point) == typeid(const char *)) \
{ \
delete [] point; \
} \
else \
{ \
free( (void *)point);\
} \
(point) = NULL; \
}\
else \
{ \
debug("CleanData: Trying to clean null Data from tile %s: function: %s: lines: %d", __FILE__, __PRETTY_FUNCTION__, __LINE__); \
(point) = NULL; \
} \
} while(0)
#define CleanData(point) \
do \
{ \
if(point) \
{ \
if(typeid(point) == typeid(char *) || typeid(point) == typeid(const char *)) \
{ \
delete [] point; \
} \
else \
{ \
free( (void *)point);\
} \
(point) = NULL; \
}\
else \
{ \
debug("CleanData: Trying to clean null Data from tile %s: function: %s: lines: %d", __FILE__, __PRETTY_FUNCTION__, __LINE__); \
(point) = NULL; \
} \
} while(0)
#define DISPOSE(point) \
do \
{ \
if( (point) ) \
{ \
if( typeid((point)) == typeid(char*) || typeid((point)) == typeid(const char*) ) \
{ \
if( in_hash_table( (char*)(point) ) ) \
{ \
log_printf( "&RDISPOSE called on STRALLOC pointer: %s, line %d\n", __FILE__, __LINE__ ); \
log_string( "Attempting to correct." ); \
if( str_free( (char*)(point) ) == -1 ) \
log_printf( "&RSTRFREEing bad pointer: %s, line %d\n", __FILE__, __LINE__ ); \
} \
else \
delete[] (point); \
} \
else \
free( (point) ); \
(point) = NULL; \
} \
else \
(point) = NULL; \
} while(0)
#endif
void show_list_to_char( OBJ_DATA * list, CHAR_DATA * ch, bool fShort,
bool fShowNothing )
{
char buf[MAX_STRING_LENGTH];
char **prgpstrShow;
int *prgnShow;
char *pstrShow;
OBJ_DATA *obj;
OBJ_DATA *obj_next;
int nShow;
int iShow;
int count;
bool fCombine;
if ( ch->desc == NULL )
return;
/*
* Alloc space for output lines.
*/
count = 0;
for ( obj = list; obj != NULL; obj = obj_next )
{
obj_next = obj->next_content;
count++;
}
/*
* If there were no objects in the list, return and do nothing.
*/
if ( count <= 0 )
return;
prgpstrShow = (char **)calloc(count,sizeof(char *));
prgnShow = (int *)calloc(count,sizeof(int)); //crashes here
nShow = 0;
/*
* Format the list of objects.
*/
for ( obj = list; obj != NULL; obj = obj_next )
{
obj_next = obj->next_content;
if(obj->wear_loc != LOC_NONE)
continue;
if (can_see_obj(ch, obj) && !IS_SET(obj->extra_flags, ITEM_NOLONG))
{
pstrShow = format_obj_to_char( obj, ch, fShort );
fCombine = FALSE;
if ( IS_NPC( ch ) || IS_SET( ch->comm, COMM_COMBINE ) )
{
/*
* Look for duplicates, case sensitive.
* Matches tend to be near end so run loop backwords.
*/
for ( iShow = nShow - 1; iShow >= 0; iShow– )
{
if ( !strcmp( prgpstrShow[iShow], pstrShow ) )
{
prgnShow[iShow]++;
fCombine = TRUE;
break;
}
}
}
/*
* Couldn't combine, or didn't want to.
*/
if ( !fCombine )
{
prgpstrShow[nShow] = str_dup( pstrShow );
prgnShow[nShow] = 1;
nShow++;
}
}
else
;
}
/*
* Output the formatted list.
*/
for ( iShow = 0; iShow < nShow; iShow++ )
{
if ( IS_NPC( ch ) || IS_SET( ch->comm, COMM_COMBINE ) )
{
if ( prgnShow[iShow] != 1 )
{
sprintf( buf, "(%2d) ", prgnShow[iShow] );
page_to_char( buf, ch );
}
else
{
page_to_char( " ", ch );
}
}
page_to_char( prgpstrShow[iShow], ch );
page_to_char( "\n\r`w", ch );
freeData(prgpstrShow[iShow] );
}
if ( fShowNothing && nShow == 0 )
{
if ( IS_NPC( ch ) || IS_SET( ch->comm, COMM_COMBINE ) )
send_to_char( " ", ch );
send_to_char( "Nothing.\n\r`w", ch );
}
/*
* Clean up.
*/
freeData(prgpstrShow);
free(prgnShow);
return;
}
#define CREATE(result, type, number) \
do \
{ \
if (!((result) = (type *) calloc ((number), sizeof(type)))) \
{ \
perror("malloc failure"); \
fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__, __LINE__ ); \
abort(); \
} \
} while(0)
Mon Nov 13 20:12:38 2006 :: Aidan left the game
==7894==
==7894== Invalid write of size 1
==7894== at 0x80961D7: game_loop(int) (comm.c:494)
==7894== by 0x80965E3: main (comm.c:235)
==7894== by 0x40363916: __libc_start_main (in /lib/libc-2.3.2.so)
==7894== by 0x8049660: ??? (start.S:81)
==7894== Address 0x45C7AF02 is 4126 bytes inside a block of size 6212 free'd
==7894== at 0x4002AEBC: free (vg_replace_malloc.c:231)
==7894== by 0x8095B5D: close_socket(descriptor_data*) (comm.c:752)
==7894== by 0x804DABC: do_quit(char_data*, char*) (act_comm.c:1258)
==7894== by 0x80BA368: interpret(char_data*, char*) (interp.c:850)
Now, the odd thing about this error is that it only does it once. After the first character logs out, it never returns.
d->incomm[0] = '\0'; <–comm.c line 494
free(dclose); <–comm.c line 752
Anyone have any ideas/suggestions?
Thanks