Browse Source

Fix a bunch of memory leaks

Daniele Bartolini 12 years ago
parent
commit
5dced42527
3 changed files with 12 additions and 4 deletions
  1. 3 0
      engine/Device.cpp
  2. 7 4
      engine/compilers/tga/TGACompiler.cpp
  3. 2 0
      engine/resource/LuaResource.h

+ 3 - 0
engine/Device.cpp

@@ -123,6 +123,7 @@ bool Device::init(int argc, char** argv)
 			if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir))
 			{
 				CE_DELETE(m_allocator, m_bundle_compiler);
+				m_allocator.clear();
 				Log::e("Exiting.");
 				exit(EXIT_FAILURE);
 			}
@@ -130,6 +131,7 @@ bool Device::init(int argc, char** argv)
 			if (!m_continue)
 			{
 				CE_DELETE(m_allocator, m_bundle_compiler);
+				m_allocator.clear();
 				exit(EXIT_SUCCESS);
 			}
 		}
@@ -199,6 +201,7 @@ bool Device::init(int argc, char** argv)
 	m_resource_manager->flush();
 	m_lua_environment->load((LuaResource*) m_resource_manager->data(luagame_id));
 	m_lua_environment->call_global("init", 0);
+	m_resource_manager->unload(luagame_id);
 
 	if (m_quit_after_init == 1)
 	{

+ 7 - 4
engine/compilers/tga/TGACompiler.cpp

@@ -42,10 +42,6 @@ TGACompiler::TGACompiler() :
 //-----------------------------------------------------------------------------
 TGACompiler::~TGACompiler()
 {
-	if (m_texture_data)
-	{
-		default_allocator().deallocate(m_texture_data);
-	}
 }
 
 //-----------------------------------------------------------------------------
@@ -141,6 +137,13 @@ void TGACompiler::write_impl(File* out_file)
 {
 	out_file->write((char*)&m_texture_header, sizeof(TextureHeader));
 	out_file->write((char*)m_texture_data, m_texture_data_size);
+
+	if (m_texture_data)
+	{
+		default_allocator().deallocate(m_texture_data);
+		m_texture_data_size = 0;
+		m_texture_data = NULL;
+	}
 }
 
 //-----------------------------------------------------------------------------

+ 2 - 0
engine/resource/LuaResource.h

@@ -60,6 +60,8 @@ public:
 		res->m_data = (uint8_t*) allocator.allocate(file_size);
 		file->read(res->m_data, file_size);
 
+		bundle.close(file);
+
 		return res;
 	}