summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-07-31 15:05:58 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-07-31 15:05:58 +0000
commit7e339a2121968741563b6195c962ed87f961c9ef (patch)
treecce14492e383415b61446e4f2d78f2dac28e446e /src/map/script.c
parent1dc870fd9c20e3d37470e5b29e3249202f82afbd (diff)
downloadhercules-7e339a2121968741563b6195c962ed87f961c9ef.tar.gz
hercules-7e339a2121968741563b6195c962ed87f961c9ef.tar.bz2
hercules-7e339a2121968741563b6195c962ed87f961c9ef.tar.xz
hercules-7e339a2121968741563b6195c962ed87f961c9ef.zip
- Fixed a possible crash in the main script engine when restoring previous script.
- Fixed sleep.tick not being set back to 0 before resuming execution, which leads to scripts that are continously executed even when they already ended (they do nothing but waste resources) - Fixed a pair of free -> aFree used on stacks, which would lead to memory manager reporting leaks where there aren't. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@8000 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 25f943d96..8d30e9fd7 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2641,6 +2641,8 @@ int run_script_timer(int tid, unsigned int tick, int id, int data)
}
node = node->next;
}
+ //Cancel tick value or run_script_main can get into an infinite loop by always delaying execution. [Skotlex]
+ st->sleep.tick = 0;
run_script_main(st);
return 0;
}
@@ -2774,13 +2776,15 @@ void run_script_main(struct script_state *st)
run_script_timer, st->sleep.charid, (int)st);
linkdb_insert(&sleep_db, (void*)st->oid, st);
//Restore previous script
- sd->st = bk_st;
- sd->npc_id = bk_npcid;
- bk_st = NULL; //Remove tag for removal.
+ if (sd) {
+ sd->st = bk_st;
+ sd->npc_id = bk_npcid;
+ bk_st = NULL; //Remove tag for removal.
+ }
}
else if(st->state != END && sd){
//Resume later (st is already attached to player).
- if(bk_st && sd->st != bk_st)
+ if(bk_st)
ShowWarning("Unable to restore stack! Double continuation!\n");
} else {
//Dispose of script.
@@ -3247,7 +3251,7 @@ int do_final_script()
while(n) {
struct script_state *st = (struct script_state *)n->data;
script_free_stack(st->stack);
- free(st);
+ aFree(st);
n = n->next;
}
linkdb_final(&sleep_db);
@@ -3295,7 +3299,7 @@ int script_reload()
while(n) {
struct script_state *st = (struct script_state *)n->data;
script_free_stack(st->stack);
- free(st);
+ aFree(st);
n = n->next;
}
linkdb_final(&sleep_db);
@@ -12297,6 +12301,7 @@ int buildin_awake(struct script_state *st)
delete_timer(tst->sleep.timer, run_script_timer);
node = script_erase_sleepdb(node);
tst->sleep.timer = -1;
+ tst->sleep.tick = 0;
run_script_main(tst);
} else {
node = node->next;