Browse Source

Fixed a small memory leak if love.physics.newChainShape errors

Alex Szpakowski 11 years ago
parent
commit
760f8220fa
1 changed files with 14 additions and 6 deletions
  1. 14 6
      src/modules/physics/box2d/Physics.cpp

+ 14 - 6
src/modules/physics/box2d/Physics.cpp

@@ -149,16 +149,24 @@ int Physics::newChainShape(lua_State *L)
 		lua_pop(L, 2);
 	}
 
-	if (loop)
-		s->CreateLoop(vecs, vcount);
-	else
-		s->CreateChain(vecs, vcount);
+	try
+	{
+		if (loop)
+			s->CreateLoop(vecs, vcount);
+		else
+			s->CreateChain(vecs, vcount);
+	}
+	catch (love::Exception &)
+	{
+		delete[] vecs;
+		throw;
+	}
 
-	ChainShape *c = new ChainShape(s);
 	delete[] vecs;
 
-	luax_pushtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, c);
+	ChainShape *c = new ChainShape(s);
 
+	luax_pushtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, c);
 	return 1;
 }