From 33b8fd47955eeab26cede233b14d683b8e0491b8 Mon Sep 17 00:00:00 2001 From: celest Date: Wed, 23 Mar 2005 15:26:52 +0000 Subject: * Fixed alot of memory leaks * Added stray memory cleaning routine to db.c git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1275 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/map.c | 108 ++++++++++++++++++++++++++-------------------------------- src/map/npc.c | 92 ++++++++++++++++++++++++++++++++++--------------- src/map/pc.c | 5 +++ src/map/pc.h | 1 + 4 files changed, 118 insertions(+), 88 deletions(-) (limited to 'src/map') diff --git a/src/map/map.c b/src/map/map.c index 60d41b84e..9dcf541c1 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1697,24 +1697,24 @@ int map_addnpc(int m,struct npc_data *nd) { } void map_removenpc(void) { - int i,m,n=0; - - for(m=0;mbl,2); - map_delblock(&map[m].npc[i]->bl); - numdb_erase(id_db,map[m].npc[i]->bl.id); - if(map[m].npc[i]->bl.subtype==SCRIPT) { -// aFree(map[m].npc[i]->u.scr.script); -// aFree(map[m].npc[i]->u.scr.label_list); - } - aFree(map[m].npc[i]); - map[m].npc[i] = NULL; - n++; - } - } - } + int i,m,n=0; + + for(m=0;mbl,2); + map_delblock(&map[m].npc[i]->bl); + numdb_erase(id_db,map[m].npc[i]->bl.id); + if(map[m].npc[i]->bl.subtype==SCRIPT) { + aFree(map[m].npc[i]->u.scr.script); + aFree(map[m].npc[i]->u.scr.label_list); + } + aFree(map[m].npc[i]); + map[m].npc[i] = NULL; + n++; + } + } + } sprintf(tmp_output,"Successfully removed and freed from memory '"CL_WHITE"%d"CL_RESET"' NPCs.\n",n); ShowStatus(tmp_output); @@ -3097,29 +3097,20 @@ int flush_timer(int tid, unsigned int tick, int id, int data){ return 0; } -int id_db_final(void *k,void *d,va_list ap) +int id_db_final(void *k,void *d,va_list ap) { return 0; } +int map_db_final(void *k,void *d,va_list ap) { return 0; } +int nick_db_final(void *k,void *d,va_list ap) { - struct mob_data *id; - nullpo_retr(0, id = (struct mob_data*)d); - if(id->lootitem) - aFree(id->lootitem); - if(id) - aFree(id); + char *p = d; + if (p) aFree(p); return 0; } - -int map_db_final(void *k,void *d,va_list ap) +int charid_db_final(void *k,void *d,va_list ap) { - struct map_data *id; - nullpo_retr(0, id = (struct map_data*)d); - if(id->gat) - aFree(id->gat); - if(id) - aFree(id); + struct charid2nick *p = d; + if (p) aFree(p); return 0; } -int nick_db_final(void *k,void *d,va_list ap){ return 0; } -int charid_db_final(void *k,void *d,va_list ap){ return 0; } int cleanup_sub(struct block_list *bl, va_list ap) { nullpo_retr(0, bl); @@ -3152,12 +3143,12 @@ int cleanup_sub(struct block_list *bl, va_list ap) { *------------------------------------------ */ void do_final(void) { - int map_id, i; + int i; ShowStatus("Terminating...\n"); - for (map_id = 0; map_id < map_num;map_id++) - if(map[map_id].m) - map_foreachinarea(cleanup_sub, map_id, 0, 0, map[map_id].xs, map[map_id].ys, 0, 0); + for (i = 0; i < map_num; i++) + if(map[i].m) + map_foreachinarea(cleanup_sub, i, 0, 0, map[i].xs, map[i].ys, 0, 0); #ifndef TXT_ONLY chrif_char_reset_offline(); @@ -3165,38 +3156,35 @@ void do_final(void) { chrif_flush_fifo(); - for (i = 0; i < fd_max; i++) - delete_session(i); - -#if 0 - map_removenpc(); - -// do_final_timer(); (we used timer_final() instead) - timer_final(); -// numdb_final(id_db, id_db_final); - strdb_final(map_db, map_db_final); - strdb_final(nick_db, nick_db_final); - numdb_final(charid_db, charid_db_final); - +//#if 0 // why is this here? >_> do_final_chrif(); // この内部でキャラを全て切断する + do_final_npc(); +// map_removenpc(); do_final_script(); do_final_itemdb(); do_final_storage(); do_final_guild(); + do_final_party(); + do_final_pc(); do_final_pet(); -/* - for(i=0;ichat_id && (cd=(struct chat_data*)map_id2bl(nd->chat_id))){ + aFree (cd); + cd = NULL; + } + if (nd->bl.subtype == SCRIPT) { + if (nd->u.scr.timer_event) + aFree(nd->u.scr.timer_event); + if (nd->u.scr.src_id==0) { + if(nd->u.scr.script) { + aFree(nd->u.scr.script); + nd->u.scr.script=NULL; + } + if (nd->u.scr.label_list) { + aFree(nd->u.scr.label_list); + nd->u.scr.label_list = NULL; + } + } + } + clif_clearchar_area(&nd->bl, 2); + map_delblock(&nd->bl); + map_deliddb(&nd->bl); + aFree(nd); + nd = NULL; + return 0; +} static int ev_db_final(void *key,void *data,va_list ap) { aFree(data); @@ -2326,6 +2356,30 @@ static int ev_db_final(void *key,void *data,va_list ap) static int npcname_db_final(void *key,void *data,va_list ap) { return 0; +} +/*========================================== + * + *------------------------------------------ + */ +int npc_reload(void) +{ + struct npc_data *nd; + struct block_list *bl; + int i; + + if(ev_db) + strdb_final(ev_db,ev_db_final); + if(npcname_db) + strdb_final(npcname_db,npcname_db_final); + + for (i = START_NPC_NUM; i < npc_id; i++) { + if((bl = map_id2bl(i)) && bl->type == BL_NPC && (nd = (struct npc_data *)bl)) + npc_unload(nd); + } + + return 0; + + } /*========================================== * 終了 @@ -2337,7 +2391,6 @@ int do_final_npc(void) struct block_list *bl; struct npc_data *nd; struct mob_data *md; - struct chat_data *cd; struct pet_data *pd; if(ev_db) @@ -2345,31 +2398,14 @@ int do_final_npc(void) if(npcname_db) strdb_final(npcname_db,npcname_db_final); - for(i=START_NPC_NUM;itype == BL_NPC && (nd = (struct npc_data *)bl)){ - if(nd->chat_id && (cd=(struct chat_data*)map_id2bl(nd->chat_id))){ - aFree(cd); - cd = NULL; - } - if(nd->bl.subtype == SCRIPT){ - if(nd->u.scr.timer_event) - aFree(nd->u.scr.timer_event); - if(nd->u.scr.src_id==0){ - if(nd->u.scr.script){ - aFree(nd->u.scr.script); - nd->u.scr.script=NULL; - } - if(nd->u.scr.label_list){ - aFree(nd->u.scr.label_list); - nd->u.scr.label_list = NULL; - } - } - } - aFree(nd); - nd = NULL; - }else if(bl->type == BL_MOB && (md = (struct mob_data *)bl)){ - if(md->lootitem){ + npc_unload(nd); + }else if (bl->type == BL_MOB && (md = (struct mob_data *)bl)){ + if (md->lootitem){ aFree(md->lootitem); md->lootitem = NULL; } @@ -2415,10 +2451,10 @@ int do_init_npc(void) // comparing only the first 24 chars of labels that are 50 chars long isn't that nice // will cause "duplicated" labels where actually no dup is... //ev_db=strdb_init(24); - ev_db=strdb_init(51); - npcname_db=strdb_init(24); + ev_db = strdb_init(51); + npcname_db = strdb_init(24); - ev_db->release = ev_release; + ev_db->release = ev_release; memset(&ev_tm_b,-1,sizeof(ev_tm_b)); diff --git a/src/map/pc.c b/src/map/pc.c index 07e712dbe..8c0857d4b 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -7234,6 +7234,11 @@ int pc_readdb(void) * pc? 係初期化 *------------------------------------------ */ +void do_final_pc(void) { + if (gm_account) + aFree(gm_account); + return; +} int do_init_pc(void) { pc_readdb(); diff --git a/src/map/pc.h b/src/map/pc.h index 242ae3147..8c4f96529 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -202,6 +202,7 @@ int pc_delspiritball(struct map_session_data *sd,int,int); int pc_eventtimer(int tid,unsigned int tick,int id,int data); // for npc_dequeue int do_init_pc(void); +void do_final_pc(void); enum {ADDITEM_EXIST,ADDITEM_NEW,ADDITEM_OVERAMOUNT}; -- cgit v1.2.3-70-g09d2