Browse Source

Fixed memory leak from pet imports (#5283)

Fixes #5279

Thanks to @mplaten
Lemongrass3110 4 years ago
parent
commit
c86a5a4536
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/map/pet.cpp

+ 10 - 0
src/map/pet.cpp

@@ -373,6 +373,11 @@ uint64 PetDatabase::parseBodyNode( const YAML::Node &node ){
 			return 0;
 		}
 
+		if( pet->pet_bonus_script != nullptr ){
+			aFree( pet->pet_bonus_script );
+			pet->pet_bonus_script = nullptr;
+		}
+
 		pet->pet_bonus_script = parse_script( script.c_str(), this->getCurrentFile().c_str(), node["Script"].Mark().line + 1, SCRIPT_IGNORE_EXTERNAL_BRACKETS );
 	}else{
 		if( !exists ){
@@ -387,6 +392,11 @@ uint64 PetDatabase::parseBodyNode( const YAML::Node &node ){
 			return 0;
 		}
 
+		if( pet->pet_support_script != nullptr ){
+			aFree( pet->pet_support_script );
+			pet->pet_support_script = nullptr;
+		}
+
 		pet->pet_support_script = parse_script( script.c_str(), this->getCurrentFile().c_str(), node["SupportScript"].Mark().line + 1, SCRIPT_IGNORE_EXTERNAL_BRACKETS );
 	}else{
 		if( !exists ){