Browse Source

- Fixed script code data not being free'd if a player quits in the middle of a script.
- Modified run_script so that when there are leaks, it will report the place where run_script was called from as source rather than the inner code of run_script (for debugging purposes)


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8057 54d463be-8e91-2dee-dedb-b68131a5f0ec

skotlex 19 years ago
parent
commit
abcf47cd67
4 changed files with 26 additions and 6 deletions
  1. 5 0
      Changelog-Trunk.txt
  2. 7 0
      src/map/map.c
  3. 11 5
      src/map/script.c
  4. 3 1
      src/map/script.h

+ 5 - 0
Changelog-Trunk.txt

@@ -4,6 +4,11 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2006/08/02
+	* Fixed script code data not being free'd if a player quits in the middle
+	  of a script. [Skotlex]
+	* Modified run_script so that when there are leaks, it will report the
+	  place where run_script was called from as source rather than the inner code
+	  of run_script (for debugging purposes) [Skotlex]
 	* Made recursive master check the default (otherwise it messes skill -> pet
 	  -> player kind of herarchies) and cleaned up some the battle_get_master
 	  code to prevent infinite loops in the weird case someone specifies that

+ 7 - 0
src/map/map.c

@@ -1695,6 +1695,13 @@ int map_quit(struct map_session_data *sd) {
 		sd->regstr = NULL;
 		sd->regstr_num = 0;
 	}
+	if (sd->st) {
+		if (sd->st->stack)
+			script_free_stack (sd->st->stack);
+		aFree(sd->st);
+		sd->st = NULL;
+		sd->npc_id = 0;
+	}
 	if(sd->fd)
   	{	//Player will be free'd on save-ack. [Skotlex]
 		if (session[sd->fd])

+ 11 - 5
src/map/script.c

@@ -2500,7 +2500,9 @@ int run_func(struct script_state *st)
  */
 void run_script_main(struct script_state *st);
 
-void run_script(struct script_code *rootscript,int pos,int rid,int oid)
+//FIXME: Temporary replacement to locate the leak source.
+//void run_script(struct script_code *rootscript,int pos,int rid,int oid)
+void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno)
 {
 	struct script_state *st;
 	struct map_session_data *sd=NULL;
@@ -2513,14 +2515,18 @@ void run_script(struct script_code *rootscript,int pos,int rid,int oid)
 		//Resume script.
 		st = sd->st;
 	} else {
-		st = aCalloc(sizeof(struct script_state), 1);
+//		st = aCalloc(sizeof(struct script_state), 1);
+		st = _mcalloc(sizeof(struct script_state), 1, file, lineno, __func__);
 		// the script is different, make new script_state and stack
-		st->stack = aMalloc (sizeof(struct script_stack));
+//		st->stack = aMalloc (sizeof(struct script_stack));
+		st->stack = _mmalloc(sizeof(struct script_stack), file, lineno, __func__);
 		st->stack->sp=0;
 		st->stack->sp_max=64;
-		st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
+//		st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
+		st->stack->stack_data = (struct script_data *)_mcalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]), file, lineno, __func__);
 		st->stack->defsp = st->stack->sp;
-		st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
+//		st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
+		st->stack->var_function = _mcalloc(1, sizeof(struct linkdb_node*), file, lineno, __func__);
 		st->state  = RUN;
 		st->script = rootscript;
 	}

+ 3 - 1
src/map/script.h

@@ -62,7 +62,9 @@ struct script_state {
 };
 
 struct script_code* parse_script(unsigned char *,const char*,int);
-void run_script(struct script_code*,int,int,int);
+void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno);
+//void run_script(struct script_code*,int,int,int);
+#define run_script(sc,pos,rid,oid) run_script_sub(sc,pos,rid,oid,__FILE__,__LINE__)
 
 int set_var(struct map_session_data *sd, char *name, void *val);
 int conv_num(struct script_state *st,struct script_data *data);