diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-05-23 18:16:25 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-05-23 18:16:25 +0000 |
commit | 9ac07b029ea3a97a621d6b817b87cf071d38da5c (patch) | |
tree | d5f98e048b729102fbcdf8f625c0e28bcb297142 /src/map | |
parent | 6706fe64d7b12ae79b1255850dd1df6d2a0b7877 (diff) | |
download | hercules-9ac07b029ea3a97a621d6b817b87cf071d38da5c.tar.gz hercules-9ac07b029ea3a97a621d6b817b87cf071d38da5c.tar.bz2 hercules-9ac07b029ea3a97a621d6b817b87cf071d38da5c.tar.xz hercules-9ac07b029ea3a97a621d6b817b87cf071d38da5c.zip |
- Some cleanup of run_script, should fix the memory leak there.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6718 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/script.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/map/script.c b/src/map/script.c index b5273721b..cde146b1a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11350,8 +11350,10 @@ int run_script_main(struct script_state *st) break;
}
- if(st->state == END)
+ if(st->state == END) {
script_free_stack (st->stack);
+ st->stack = NULL;
+ }
return 0;
}
@@ -11374,7 +11376,7 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid) if (rootscript == NULL || pos < 0)
return -1;
- st = calloc(sizeof(struct script_state), 1);
+ st = aCalloc(sizeof(struct script_state), 1);
if ((sd = map_id2sd(rid)) && sd->stack && sd->npc_scriptroot == rootscript){
// we have a stack for the same script, should continue exec.
@@ -11412,12 +11414,12 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid) // let's run that stuff
run_script_main(st);
- if(st){
- if(st->sleep.tick > 0) {
- // スタック情報をsleep_dbに保存
- unsigned int tick = gettick()+st->sleep.tick;
- st->sleep.charid = sd ? sd->char_id : 0;
- st->sleep.timer = add_timer(tick, run_script_timer, st->sleep.charid, (int)st);
+ if(st->state != END){
+ if(st->sleep.tick > 0)
+ { //Delay execution
+ st->sleep.charid = sd?sd->char_id:0;
+ st->sleep.timer = add_timer(gettick()+st->sleep.tick,
+ run_script_timer, st->sleep.charid, (int)st);
linkdb_insert(&sleep_db, (void*)st->oid, st);
} else if (sd) {
// script is not finished, store data in sd.
@@ -11428,25 +11430,27 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid) if (bck_stack) //Get rid of the backup as it can't be restored.
script_free_stack (bck_stack);
}
- } else {
- // and if there was a sd associated - zero vars.
- if (sd) {
- //Clear or restore previous script.
- sd->npc_script = bck_script;
- sd->npc_scriptroot = bck_scriptroot;
- sd->npc_scriptstate = bck_scriptstate;
- sd->stack = bck_stack;
- //Since the script is done, save any changed account variables [Skotlex]
- if (sd->state.reg_dirty&2)
- intif_saveregistry(sd,2);
- if (sd->state.reg_dirty&1)
- intif_saveregistry(sd,1);
- }
- //aFree(st);
- return 0;
+ return st->pos;
}
-
- return st->pos;
+ //Script finished.
+ if (sd)
+ { //Clear or restore previous script.
+ sd->npc_script = bck_script;
+ sd->npc_scriptroot = bck_scriptroot;
+ sd->npc_scriptstate = bck_scriptstate;
+ sd->stack = bck_stack;
+ //Since the script is done, save any changed account variables [Skotlex]
+ if (sd->state.reg_dirty&2)
+ intif_saveregistry(sd,2);
+ if (sd->state.reg_dirty&1)
+ intif_saveregistry(sd,1);
+ }
+ if(st->stack) {
+ script_free_stack (st->stack);
+ st->stack = NULL;
+ }
+ aFree(st);
+ return 0;
}
/*==========================================
|