The ADD2LAST BUG for EmberMUD Fix Sheet by Rindar (Ron Cole) Fix by Raven (Laurie Zenner) The Bug: After a lot of people start gossiping, does it seems like the MUD crashes? If so, it is probably caused by a memory leak bug in the function ADD2LAST. The Bugfix: You need to modify the functions "void add2last" and "void add2last_imm" in act_comm.c. If you do not want to mess with modifying the function one line at a time, the entire code snippets for each function have been included at the bottom of this sheet. Otherwise, do the following: 1) Open act_comm.c 2) Find the function "void add2last" 3) Find the line: free_string(tmp->msg); This is how it looks in the code: free_string(tmp->msg); if (tmp->sender!=NULL) free_string(tmp->sender); 4) Note out the statement: /* if (tmp->sender!=NULL) free_string(tmp->sender); */ And add the following statement after it: if (strlen(tmp->sender)>0 && tmp->sender!=NULL) free_string(tmp->sender); The new code should look like this: free_string(tmp->msg); /* if (tmp->sender!=NULL) free_string(tmp->sender); */ if (strlen(tmp->sender)>0 && tmp->sender!=NULL) free_string(tmp->sender); free_mem(tmp, sizeof(LAST_DATA)); 5) Find the function "void add2last_imm". 6) Find the section of the function that looks like this: flast = flast->next; free_string(tmp->msg); if (strlen(tmp->sender)>0) free_string(tmp->sender); free_mem(tmp, sizeof(LAST_DATA)); last_length--; 7) Re-order this section and add a new free_string test. It should look like this: flast = flast->next; if (strlen(tmp->msg) > 0 && tmp->msg!=NULL) free_string(tmp->msg); /* if (strlen(tmp->sender)>0) free_string(tmp->sender); */ if (strlen(tmp->sender)>0 && tmp->sender!=NULL) free_string(tmp->sender); free_mem(tmp, sizeof(LAST_DATA)); last_length--; 8) Recompile. You are done. Notes: We have yet to give this function an extremely rough trial, but we believe we have completely fixed the gossip leak. If you know of other leaks in the function add2last, feel free to e-mail it to me. Thanks! -= Rindar clogar@concentric.net ** Note: This function is provided "as is" and may be used so long as 1) The author's name is kept at the top of the function (if requested) and 2) all other previous licensing aggreements are abided by. The author assumes no responsibility for problems that occur through use or install- ation, including lost wages, bugs, deletions, downtimes, etc... Use at your own risk. All new code is copyrighted by its author. void add2last( char *argument, CHAR_DATA *ch ) { LAST_DATA * tmp; if (last_list == NULL) { last_list = alloc_mem(sizeof(LAST_DATA)); last_list->next = NULL; flast = last_list; last_list->msg = str_dup(argument); last_list->level = ch->invis_level; last_list->hidden = (IS_SET(ch->act,PLR_WIZINVIS)) ? TRUE : FALSE; last_list->sender = str_dup(ch->name); last_length++; } else { if (last_length >= MAX_LAST_LENGTH) { tmp = flast; flast = flast->next; if (strlen(tmp->msg) > 0 && tmp->msg!=NULL) free_string(tmp->msg); /* if (strlen(tmp->sender)>0) free_string(tmp->sender); */ if (strlen(tmp->sender)>0 && tmp->sender!=NULL) free_string(tmp->sender); free_mem(tmp, sizeof(LAST_DATA)); last_length--; } last_list->next = alloc_mem(sizeof(LAST_DATA)); last_list = last_list->next; last_list->next = NULL; last_list->msg = str_dup(argument); last_list->sender = str_dup(ch->name); last_list->level = ch->invis_level; last_list->hidden = (IS_SET(ch->act,PLR_WIZINVIS)) ? TRUE : FALSE; last_length++; } } void add2last_imm( char *argument, CHAR_DATA *ch) { LAST_DATA * tmp; if (last_imm == NULL) { last_imm = alloc_mem(sizeof(LAST_DATA)); last_imm->next = NULL; flast_imm = last_imm; last_imm->msg = str_dup(argument); last_imm->sender = str_dup(ch->name); last_imm->level = ch->invis_level; last_imm->hidden = (IS_SET(ch->act,PLR_WIZINVIS)) ? TRUE : FALSE; last_imm_length++; } else { if (last_imm_length >= MAX_LAST_LENGTH) { tmp = flast_imm; flast_imm = flast_imm->next; free_string(tmp->msg); /* if (tmp->sender!=NULL) free_string(tmp->sender); */ if (strlen(tmp->sender)>0 && tmp->sender!=NULL) free_string(tmp->sender); free_mem(tmp, sizeof(LAST_DATA)); last_imm_length--; } last_imm->next = alloc_mem(sizeof(LAST_DATA)); last_imm = last_imm->next; last_imm->next = NULL; last_imm->msg = str_dup(argument); last_imm->sender = str_dup(ch->name); last_imm->level = ch->invis_level; last_imm->hidden = (IS_SET(ch->act,PLR_WIZINVIS)) ? TRUE : FALSE; last_imm_length++; } } ============================================================================= / ______ _______ ____ _____ ___ __ _ ______ ____ ____ _____ / \ | ____|__ __| _ \ / ____\ / _ \| \ / | ____| / __ \| _ \ / ____\ \ / | |__ | | | |_| | | | |_| | |\/| | |___ | | | | |_| | | / / | ___| | | | ___/| | __| _ | | | | ____| | | | | __/| | ___ \ \ | | | | | | | |___| | | | | | | | |____ | |__| | |\ \| |___| | / / |_| |_| |_| o \_____/|_| |_|_| |_|______|o \____/|_| \_|\_____/ \ \ / ============================================================================ ------------------------------------------------------------------------------ ftp://ftp.game.org/pub/mud FTP.GAME.ORG http://www.game.org/ftpsite/ ------------------------------------------------------------------------------ This file came from FTP.GAME.ORG, the ultimate source for MUD resources. ------------------------------------------------------------------------------