summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshinomori <shinomori@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-02-14 20:50:40 +0000
committershinomori <shinomori@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-02-14 20:50:40 +0000
commit8fa0cea72c24c464e4e43b081316af34dcf30af7 (patch)
treede29a771617152dcae91189222be42efd19a8ead
parent61980833a1b7ffe229712f782f14425ab4fef90e (diff)
downloadhercules-8fa0cea72c24c464e4e43b081316af34dcf30af7.tar.gz
hercules-8fa0cea72c24c464e4e43b081316af34dcf30af7.tar.bz2
hercules-8fa0cea72c24c464e4e43b081316af34dcf30af7.tar.xz
hercules-8fa0cea72c24c464e4e43b081316af34dcf30af7.zip
fixed memory leak in guild_gvg_eliminate_timer and timer handling in npc_event_timer [Shinomori]
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1106 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--src/map/guild.c20
-rw-r--r--src/map/npc.c27
2 files changed, 36 insertions, 11 deletions
diff --git a/src/map/guild.c b/src/map/guild.c
index 64e2b29d2..72bf302f0 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -1500,15 +1500,21 @@ int guild_agit_end(void)
int guild_gvg_eliminate_timer(int tid,unsigned int tick,int id,int data)
{ // Run One NPC_Event[OnAgitEliminate]
- size_t len = strlen((const char*)data);
- char *evname=(char*)aCallocA(len + 4,sizeof(char));
+ char *name = (char*)data;
+ size_t len = (name) ? strlen(name) : 0;
+ // the rest is dangerous, but let it crash,
+ // if this happens, it's ruined anyway
+ char *evname=(char*)aMalloc( (len + 4) * sizeof(char));
int c=0;
- if(!agit_flag) return 0; // Agit already End
- memcpy(evname,(const char *)data,len - 5);
- strcpy(evname + len - 5,"Eliminate");
- c = npc_event_do(evname);
- printf("NPC_Event:[%s] Run (%d) Events.\n",evname,c);
+ if(agit_flag) // Agit not already End
+ {
+ memcpy(evname,name,len - 5);
+ strcpy(evname + len - 5,"Eliminate");
+ c = npc_event_do(evname);
+ printf("NPC_Event:[%s] Run (%d) Events.\n",evname,c);
+ }
+ if(name) aFree(name);
return 0;
}
diff --git a/src/map/npc.c b/src/map/npc.c
index 12906a1fc..1ba55699f 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -164,12 +164,31 @@ int npc_delete(struct npc_data *nd)
*/
int npc_event_timer(int tid,unsigned int tick,int id,int data)
{
+ char *eventname = (char *)data;
+ struct event_data *ev = (struct event_data *)strdb_search(ev_db,eventname);
+ struct npc_data *nd;
struct map_session_data *sd=map_id2sd(id);
- if (sd==NULL)
- return 0;
+ size_t i;
- npc_event(sd,(const char *)data,0);
- aFree((void*)data);
+ if((ev==NULL || (nd=ev->nd)==NULL))
+ {
+ if(battle_config.error_log)
+ printf("npc_event: event not found [%s]\n",eventname);
+ }
+ else
+ {
+ for(i=0;i<MAX_EVENTTIMER;i++) {
+ if( nd->eventtimer[i]==tid ) {
+ nd->eventtimer[i]=-1;
+ npc_event(sd,eventname,0); // sd NULL check is within
+ break;
+ }
+ }
+ if(i==MAX_EVENTTIMER && battle_config.error_log)
+ printf("npc_event_timer: event timer not found [%s]!\n",eventname);
+ }
+
+ aFree(eventname);
return 0;
}