From bf26d79323ba5e263387ce41ecac2d946995dcc7 Mon Sep 17 00:00:00 2001 From: Vatiken Date: Tue, 21 Feb 2012 06:13:45 +0000 Subject: [PATCH] Bug Fix: Fixed major leak with the history system, as well as added a few more memory cleanups to make zmalloc happy. --- src/act.h | 2 ++ src/act.wizard.c | 36 ++++++++++++++++++++++++------------ src/comm.c | 9 +++++++-- src/db.c | 2 +- src/lists.c | 3 ++- src/protocol.c | 32 ++++++++++---------------------- 6 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/act.h b/src/act.h index c60a2dc..24384be 100644 --- a/src/act.h +++ b/src/act.h @@ -57,6 +57,8 @@ char *find_exdesc(char *word, struct extra_descr_data *list); void space_to_minus(char *str); /** @todo Move to a help module? */ int search_help(const char *argument, int level); +void free_history(struct char_data *ch, int type); +void free_recent_players(void); /* functions with subcommands */ /* do_commands */ ACMD(do_commands); diff --git a/src/act.wizard.c b/src/act.wizard.c index b7067fb..5dd67f0 100644 --- a/src/act.wizard.c +++ b/src/act.wizard.c @@ -2223,24 +2223,22 @@ ACMD(do_wiznet) return; } if (level > LVL_IMMORT) { - snprintf(buf1, sizeof(buf1), "@c%s: <%d> %s%s@n\r\n", GET_NAME(ch), level, emote ? "<--- " : "", argument); - snprintf(buf2, sizeof(buf1), "@cSomeone: <%d> %s%s@n\r\n", level, emote ? "<--- " : "", argument); + snprintf(buf1, sizeof(buf1), "@c%s: <%d> %s%s@n", GET_NAME(ch), level, emote ? "<--- " : "", argument); + snprintf(buf2, sizeof(buf1), "@cSomeone: <%d> %s%s@n", level, emote ? "<--- " : "", argument); } else { - snprintf(buf1, sizeof(buf1), "@c%s: %s%s@n\r\n", GET_NAME(ch), emote ? "<--- " : "", argument); - snprintf(buf2, sizeof(buf1), "@cSomeone: %s%s@n\r\n", emote ? "<--- " : "", argument); + snprintf(buf1, sizeof(buf1), "@c%s: %s%s@n", GET_NAME(ch), emote ? "<--- " : "", argument); + snprintf(buf2, sizeof(buf1), "@cSomeone: %s%s@n", emote ? "<--- " : "", argument); } for (d = descriptor_list; d; d = d->next) { if (IS_PLAYING(d) && (GET_LEVEL(d->character) >= level) && (!PRF_FLAGGED(d->character, PRF_NOWIZ)) && (d != ch->desc || !(PRF_FLAGGED(d->character, PRF_NOREPEAT)))) { - if (CAN_SEE(d->character, ch)) { - msg = strdup(buf1); - send_to_char(d->character, "%s", buf1); - } else { - msg = strdup(buf2); - send_to_char(d->character, "%s", buf2); - } + if (CAN_SEE(d->character, ch)) + msg = act(buf1, FALSE, d->character, 0, 0, TO_CHAR | DG_NO_TRIG); + else + msg = act(buf2, FALSE, d->character, 0, 0, TO_CHAR | DG_NO_TRIG); + add_history(d->character, msg, HIST_WIZNET); } } @@ -2466,7 +2464,7 @@ ACMD(do_show) struct obj_data *obj; struct descriptor_data *d; char field[MAX_INPUT_LENGTH], value[MAX_INPUT_LENGTH], - arg[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH], temp[MAX_STRING_LENGTH]; + arg[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH]; int r, g, b; char colour[16]; @@ -4948,6 +4946,20 @@ bool AddRecentPlayer(char *chname, char *chhost, bool newplr, bool cpyplr) return TRUE; } +void free_recent_players(void) +{ + struct recent_player *this; + struct recent_player *temp; + + this = recent_list; + + while((temp = this) != NULL) + { + this = this->next; + free(temp); + } +} + ACMD(do_recent) { time_t ct; diff --git a/src/comm.c b/src/comm.c index c79ffae..6adabff 100644 --- a/src/comm.c +++ b/src/comm.c @@ -370,8 +370,10 @@ int main(int argc, char **argv) free_invalid_list(); /* ban.c */ free_save_list(); /* genolc.c */ free_strings(&config_info, OASIS_CFG); /* oasis_delete.c */ - free_ibt_lists(); /* ibt.c */ - free_list(world_events); + free_ibt_lists(); /* ibt.c */ + free_recent_players(); /* act.informative.c */ + free_list(world_events); /* free up our global lists */ + free_list(global_lists); } if (last_act_message) @@ -415,6 +417,9 @@ void copyover_recover() /* read boot_time - first line in file */ i = fscanf(fp, "%ld\n", (long *)&boot_time); + + if (i != 1) + log("SYSERR: Error reading boot time."); for (;;) { fOld = TRUE; diff --git a/src/db.c b/src/db.c index bc08d9f..1e45d92 100644 --- a/src/db.c +++ b/src/db.c @@ -3165,7 +3165,7 @@ void free_char(struct char_data *ch) free(ch->player.description); for (i = 0; i < NUM_HIST; i++) if (GET_HISTORY(ch, i)) - free(GET_HISTORY(ch, i)); + free_history(ch, i); if (ch->player_specials) free(ch->player_specials); diff --git a/src/lists.c b/src/lists.c index 0cbb60c..55e356b 100644 --- a/src/lists.c +++ b/src/lists.c @@ -63,7 +63,8 @@ void free_list(struct list_data * pList) mudlog(CMP, LVL_GOD, TRUE, "List being freed while not empty."); /* Global List for debugging */ - remove_from_list(pList, global_lists); + if (pList != global_lists) + remove_from_list(pList, global_lists); free(pList); } diff --git a/src/protocol.c b/src/protocol.c index 3e5bb29..61561d8 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -10,14 +10,7 @@ Header files. ******************************************************************************/ -#include -#include -#include #include -#include -#include -#include - #include "protocol.h" /****************************************************************************** @@ -292,7 +285,7 @@ protocol_t *ProtocolCreate( void ) } } - pProtocol = malloc(sizeof(protocol_t)); + pProtocol = (protocol_t *) malloc(sizeof(protocol_t)); pProtocol->WriteOOB = 0; pProtocol->bIACMode = false; pProtocol->bNegotiated = false; @@ -310,11 +303,11 @@ protocol_t *ProtocolCreate( void ) pProtocol->ScreenHeight = 0; pProtocol->pMXPVersion = AllocString("Unknown"); pProtocol->pLastTTYPE = NULL; - pProtocol->pVariables = malloc(sizeof(MSDP_t*)*eMSDP_MAX); + pProtocol->pVariables = (MSDP_t **) malloc(sizeof(MSDP_t*)*eMSDP_MAX); for ( i = eMSDP_NONE+1; i < eMSDP_MAX; ++i ) { - pProtocol->pVariables[i] = malloc(sizeof(MSDP_t)); + pProtocol->pVariables[i] = (MSDP_t *) malloc(sizeof(MSDP_t)); pProtocol->pVariables[i]->bReport = false; pProtocol->pVariables[i]->bDirty = false; pProtocol->pVariables[i]->ValueInt = 0; @@ -350,7 +343,8 @@ void ProtocolDestroy( protocol_t *apProtocol ) } free(apProtocol->pVariables); - free(apProtocol->pLastTTYPE); + if (apProtocol->pLastTTYPE) /* Isn't saved over copyover so may still be NULL */ + free(apProtocol->pLastTTYPE); free(apProtocol->pMXPVersion); free(apProtocol); } @@ -554,12 +548,6 @@ const char *ProtocolOutput( descriptor_t *apDescriptor, const char *apData, int case 'n': pCopyFrom = s_Clean; break; - case 'b': /* dark brown */ - pCopyFrom = ColourRGB(apDescriptor, "F110"); - break; - case 'B': /* light brown */ - pCopyFrom = ColourRGB(apDescriptor, "F410"); - break; case 'd': /* dark grey / black */ pCopyFrom = ColourRGB(apDescriptor, "F000"); break; @@ -590,10 +578,10 @@ const char *ProtocolOutput( descriptor_t *apDescriptor, const char *apData, int case 'Y': /* light yellow */ pCopyFrom = ColourRGB(apDescriptor, "F550"); break; - case 'u': /* dark blue */ + case 'b': /* dark blue */ pCopyFrom = ColourRGB(apDescriptor, "F012"); break; - case 'U': /* light blue */ + case 'B': /* light blue */ pCopyFrom = ColourRGB(apDescriptor, "F025"); break; case 'm': /* dark magenta */ @@ -1244,7 +1232,7 @@ void MSDPSetTable( descriptor_t *apDescriptor, variable_t aMSDP, const char *apV const char MsdpTableStart[] = { (char)MSDP_TABLE_OPEN, '\0' }; const char MsdpTableStop[] = { (char)MSDP_TABLE_CLOSE, '\0' }; - char *pTable = malloc(strlen(apValue) + 3); /* 3: START, STOP, NUL */ + char *pTable = (char *) malloc(strlen(apValue) + 3); /* 3: START, STOP, NUL */ strcpy(pTable, MsdpTableStart); strcat(pTable, apValue); @@ -1280,7 +1268,7 @@ void MSDPSetArray( descriptor_t *apDescriptor, variable_t aMSDP, const char *apV const char MsdpArrayStart[] = { (char)MSDP_ARRAY_OPEN, '\0' }; const char MsdpArrayStop[] = { (char)MSDP_ARRAY_CLOSE, '\0' }; - char *pArray = malloc(strlen(apValue) + 3); /* 3: START, STOP, NUL */ + char *pArray = (char *) malloc(strlen(apValue) + 3); /* 3: START, STOP, NUL */ strcpy(pArray, MsdpArrayStart); strcat(pArray, apValue); @@ -2492,7 +2480,7 @@ static char *AllocString( const char *apString ) if ( apString != NULL ) { int Size = strlen(apString); - pResult = malloc(Size+1); + pResult = (char *) malloc(Size+1); if ( pResult != NULL ) strcpy( pResult, apString ); }