From 8a21fbf0cec3af9c9a7b957fdbffb19addb0b7df Mon Sep 17 00:00:00 2001 From: faketruth Date: Tue, 27 Dec 2011 17:59:08 +0000 Subject: I think I fixed the memory leaks in the converter Updated makefile for Unix I changed how the converter works, now you simply put the .exe in the folder you want to convert and run it, it'll output all the files in ./world git-svn-id: http://mc-server.googlecode.com/svn/trunk@132 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- converter/source/cNBTData.cpp | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'converter/source/cNBTData.cpp') diff --git a/converter/source/cNBTData.cpp b/converter/source/cNBTData.cpp index 556960732..cdd88a0c0 100644 --- a/converter/source/cNBTData.cpp +++ b/converter/source/cNBTData.cpp @@ -1,3 +1,5 @@ +#include "MemoryLeak.h" + #include "cNBTData.h" #include // memcpy #include @@ -40,8 +42,10 @@ cNBTData::cNBTData( char* a_Buffer, unsigned int a_BufferSize ) m_ParseFunctions[TAG_ByteArray] = &cNBTData::ParseByteArray; - m_Buffer = a_Buffer; - m_BufferSize = a_BufferSize; + m_BufferSize = a_BufferSize; + m_Buffer = new char[m_BufferSize]; // Make a copy of the buffer + memcpy( m_Buffer, a_Buffer, m_BufferSize ); + m_Index = 0; tm = false; //tm to true will print more information for test mode @@ -479,6 +483,10 @@ void cNBTData::ParseData() } ParseTags(); } + + + delete [] m_Buffer; + m_Buffer = 0; m_BufferSize = 0; } void cNBTData::ParseTags() @@ -682,10 +690,11 @@ void cNBTData::ParseByteArray( bool a_bNamed ) int Length = ReadInt(); std::string String; - char* ByteArray = new char[ Length ]; + char* ByteArray = 0; if( Length > 0 ) { - memcpy( ByteArray, &m_Buffer[ m_Index ], Length ); + ByteArray = new char[ Length ]; + memcpy( ByteArray, &m_Buffer[ m_Index ], Length ); m_Index += Length; } @@ -856,8 +865,9 @@ void cNBTList::Serialize(std::string & a_Buffer) void cNBTData::Clear() { - while( m_CurrentCompound != this ) CloseCompound(); - m_CurrentCompound->Clear(); + while( m_CurrentCompound != this ) CloseCompound(); // Close ALL the compounds!! + + m_CurrentCompound->Clear(); // This recursively clears all compounds if( m_Buffer ) { @@ -885,10 +895,23 @@ void cNBTCompound::Clear() delete itr->second; itr->second = 0; } - m_Lists.clear(); - m_Bytes.clear(); + m_Lists.clear(); + + for( ByteArrayMap::iterator itr = m_ByteArrays.begin(); itr != m_ByteArrays.end(); itr++ ) + { + if( itr->second == 0 ) continue; + delete [] itr->second; + itr->second = 0; + } + m_ByteArrays.clear(); + + // Don't really have to do this, but meh + m_Bytes.clear(); m_Shorts.clear(); m_Integers.clear(); + m_Longs.clear(); + m_Doubles.clear(); + m_Floats.clear(); m_Strings.clear(); } -- cgit v1.2.3