diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-10-25 20:55:19 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-10-25 20:55:19 +0000 |
commit | 7d65a46135c8b8536f48f58ff2a0a26fd40932b6 (patch) | |
tree | 113f90c2f3cca9d2ab8f5a76eda84fb04822ac5b /src/map/pc.c | |
parent | 0da16e5615bfe3a964ee049c374e7154dab2049d (diff) | |
download | hercules-7d65a46135c8b8536f48f58ff2a0a26fd40932b6.tar.gz hercules-7d65a46135c8b8536f48f58ff2a0a26fd40932b6.tar.bz2 hercules-7d65a46135c8b8536f48f58ff2a0a26fd40932b6.tar.xz hercules-7d65a46135c8b8536f48f58ff2a0a26fd40932b6.zip |
- Some cleaning of the pc_eventtimer and pc enqueue code, it should fix some memory leaks when the event counter does not matches with the actual number of queued timers during logout.
- Minor typos, corrections, etc.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9072 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/pc.c')
-rw-r--r-- | src/map/pc.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/map/pc.c b/src/map/pc.c index 4a90929ea..c3e68a807 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -6139,19 +6139,16 @@ int pc_eventtimer(int tid,unsigned int tick,int id,int data) if(sd==NULL) return 0; - for(i=0;i < MAX_EVENTTIMER;i++){ - if( sd->eventtimer[i]==tid ){ - sd->eventtimer[i]=-1; - npc_event(sd,p,0); - break; - } - } - if (p) aFree(p); - if(i==MAX_EVENTTIMER) { - if(battle_config.error_log) - ShowError("pc_eventtimer: no such event timer\n"); - } + for(i=0;i < MAX_EVENTTIMER && sd->eventtimer[i]!=tid; i++); + + if(i < MAX_EVENTTIMER){ + sd->eventtimer[i]=-1; + npc_event(sd,p,0); + sd->eventcount--; + } else if(battle_config.error_log) + ShowError("pc_eventtimer: no such event timer\n"); + if (p) aFree(p); return 0; } @@ -6162,20 +6159,19 @@ int pc_eventtimer(int tid,unsigned int tick,int id,int data) int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name) { int i; + char *evname; nullpo_retr(0, sd); - for(i=0;i<MAX_EVENTTIMER;i++) - if( sd->eventtimer[i]==-1 ) - break; - if(i<MAX_EVENTTIMER){ - char *evname = aStrdup(name); - //char *evname=(char *)aMallocA((strlen(name)+1)*sizeof(char)); - //memcpy(evname,name,(strlen(name)+1)); - sd->eventtimer[i]=add_timer(gettick()+tick, - pc_eventtimer,sd->bl.id,(int)evname); - sd->eventcount++; - } + for(i=0;i<MAX_EVENTTIMER && sd->eventtimer[i]!=-1;i++); + + if(i==MAX_EVENTTIMER) + return 0; + + evname = aStrdup(name); + sd->eventtimer[i]=add_timer(gettick()+tick, + pc_eventtimer,sd->bl.id,(int)evname); + sd->eventcount++; return 0; } @@ -6246,9 +6242,9 @@ int pc_cleareventtimer(struct map_session_data *sd) char *p = (char *)(get_timer(sd->eventtimer[i])->data); delete_timer(sd->eventtimer[i],pc_eventtimer); sd->eventtimer[i]=-1; + sd->eventcount--; if (p) aFree(p); } - return 0; } |