瀏覽代碼

Memory leak fixes

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@1006 54d463be-8e91-2dee-dedb-b68131a5f0ec
(no author) 20 年之前
父節點
當前提交
0fab6904cc
共有 4 個文件被更改,包括 19 次插入5 次删除
  1. 2 0
      Changelog.txt
  2. 3 0
      src/map/map.c
  3. 13 5
      src/map/pet.c
  4. 1 0
      src/map/pet.h

+ 2 - 0
Changelog.txt

@@ -1,6 +1,8 @@
 Date	Added
 
 01/27
+        * Added memory leak fixes with temporary script variables and pets-related
+          actions, by End_of_exam / jA 1109 [celest]
         * Kick all characters when the char server disconnects from the map
           server [celest]
         * Added @changelook command for spriters to test view ID's [celest]

+ 3 - 0
src/map/map.c

@@ -1094,6 +1094,8 @@ int map_quit(struct map_session_data *sd) {
 	} 
 	strdb_erase(nick_db,sd->status.name);
 	numdb_erase(charid_db,sd->status.char_id);
+	free(sd->reg);
+	free(sd->regstr);
 
 	return 0;
 }
@@ -2626,6 +2628,7 @@ void do_final(void) {
 	do_final_itemdb();
 	do_final_storage();
 	do_final_guild();
+	do_final_pet();
 /*
 	for(i=0;i<map_num;i++){
 		if(map[i].gat) {

+ 13 - 5
src/map/pet.c

@@ -610,6 +610,7 @@ int pet_remove_map(struct map_session_data *sd)
 			pet_hungry_timer_delete(sd);
 		clif_clearchar_area(&sd->pd->bl,0);
 		map_delblock(&sd->pd->bl);
+		free(sd->pd->lootitem);
 		map_deliddb(&sd->pd->bl);
 	}
 	return 0;
@@ -653,7 +654,8 @@ int pet_return_egg(struct map_session_data *sd)
 	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
 
 	if(sd->status.pet_id && sd->pd) {
-		struct pet_data *pd=sd->pd;
+		// ルートしたItemを落とさせる
+		pet_lootitem_drop(sd->pd,sd);
 		pet_remove_map(sd);
 		sd->status.pet_id = 0;
 		sd->pd = NULL;
@@ -677,8 +679,6 @@ int pet_return_egg(struct map_session_data *sd)
 			else
 				status_calc_pc(sd,2);
 		}
-		// ルートしたItemを落とさせる
-		pet_lootitem_drop(pd,sd);
 
 		intif_save_petdata(sd->status.account_id,&sd->pet);
 		pc_makesavestatus(sd);
@@ -1382,8 +1382,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
 				else
 					add_timer(gettick()+540+i,pet_delay_item_drop2,(int)ditem,0);
 			}
-			pd->lootitem=NULL;
-			pd->lootitem=(struct item *)aCalloc(PETLOOT_SIZE,sizeof(struct item));
+			memset(pd->lootitem,0,LOOTITEM_SIZE * sizeof(struct item));
 			pd->lootitem_count = 0;
 			pd->lootitem_weight = 0;
 			pd->lootitem_timer = gettick()+10000;	//	10*1000msの間拾わない
@@ -1701,3 +1700,12 @@ int do_init_pet(void)
 	return 0;
 }
 
+int do_final_pet(void) {
+	int i;
+	for(i = 0;i < MAX_PET_DB; i++) {
+		if(pet_db[i].script) {
+			free(pet_db[i].script);
+		}
+	}
+	return 0;
+}

+ 1 - 0
src/map/pet.h

@@ -64,6 +64,7 @@ int pet_heal_timer(int tid,unsigned int tick,int id,int data); // [Valaris]
 int pet_skillattack_timer(int tid,unsigned int tick,int id,int data); // [Valaris]
 
 int do_init_pet(void);
+int do_final_pet(void);
 
 #endif