Fix using freed memory (could be the cause of queue error problem and other bugs)
authorunc0rr
Tue, 28 Oct 2008 20:56:02 +0000
changeset 1435 d4b32ee3caa6
parent 1434 75fe933483c7
child 1436 252ab509c779
Fix using freed memory (could be the cause of queue error problem and other bugs)
hedgewars/GSHandlers.inc
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Tue Oct 28 18:45:38 2008 +0000
+++ b/hedgewars/GSHandlers.inc	Tue Oct 28 20:56:02 2008 +0000
@@ -925,13 +925,13 @@
 	begin
 	x:= hwRound(Gear^.X);
 	y:= hwRound(Gear^.Y);
-	DeleteGear(Gear);
 	if Gear^.Kind = gtCase then
 		begin
 		doMakeExplosion(x, y, 25, EXPLAutoSound);
 		for i:= 0 to 63 do
 			AddGear(x, y, gtFlame, 0, _0, _0, 0);
 		end;
+	DeleteGear(Gear);
 	exit
 	end;
 
--- a/hedgewars/uGears.pas	Tue Oct 28 18:45:38 2008 +0000
+++ b/hedgewars/uGears.pas	Tue Oct 28 20:56:02 2008 +0000
@@ -85,7 +85,7 @@
                                   end;
                  end;
 
-procedure DeleteGear(Gear: PGear); forward;
+procedure DeleteGear(var Gear: PGear); forward;
 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
 //procedure AmmoFlameWork(Ammo: PGear); forward;
@@ -343,7 +343,7 @@
 AddGear:= Result
 end;
 
-procedure DeleteGear(Gear: PGear);
+procedure DeleteGear(var Gear: PGear);
 var team: PTeam;
     t: Longword;
 begin
@@ -382,7 +382,10 @@
 if CurAmmoGear = Gear then CurAmmoGear:= nil;
 if FollowGear = Gear then FollowGear:= nil;
 RemoveGearFromList(Gear);
-Dispose(Gear)
+
+Dispose(Gear);
+
+Gear:= nil
 end;
 
 function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs
@@ -1116,9 +1119,10 @@
 var i: LongInt;
 begin
 AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000);
+
 if (GameFlags and gfForts) = 0 then
-   for i:= 0 to Pred(cLandAdditions) do
-       FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048);
+	for i:= 0 to Pred(cLandAdditions) do
+		FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048);
 end;
 
 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord);