Free allocated data

Direct leak of 8 byte(s) in 2 object(s) allocated from:
    #0 0x4f08e3 in __interceptor_malloc (/home/teeworlds/servers/DDNet-Server-asan+0x4f08e3)
    #1 0x68c9d1 in CDataFileWriter::AddItem(int, int, int, void*) /home/teeworlds/src/master/src/engine/shared/datafile.cpp:666:33
    #2 0x5e4a3e in CGameContext::OnMapChange(char*, int) /home/teeworlds/src/master/src/game/server/gamecontext.cpp:3398:10
    #3 0x553473 in CServer::LoadMap(char const*) /home/teeworlds/src/master/src/engine/server/server.cpp:2235:16
    #4 0x55509e in CServer::Run() /home/teeworlds/src/master/src/engine/server/server.cpp:2440:8
    #5 0x561a56 in main /home/teeworlds/src/master/src/engine/server/server.cpp:3537:21
    #6 0x7f2349f3809a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
This commit is contained in:
def 2020-10-18 12:57:55 +02:00
parent 1081a6870c
commit c203d787d2

View file

@ -591,6 +591,12 @@ CDataFileWriter::~CDataFileWriter()
{
free(m_pItemTypes);
m_pItemTypes = 0;
for(int i = 0; i < m_NumItems; i++)
if(m_pItems[i].m_pData)
free(m_pItems[i].m_pData);
for(int i = 0; i < m_NumDatas; ++i)
if(m_pDatas[i].m_pCompressedData)
free(m_pDatas[i].m_pCompressedData);
free(m_pItems);
m_pItems = 0;
free(m_pDatas);
@ -895,9 +901,15 @@ int CDataFileWriter::Finish()
// free data
for(int i = 0; i < m_NumItems; i++)
{
free(m_pItems[i].m_pData);
m_pItems[i].m_pData = 0;
}
for(int i = 0; i < m_NumDatas; ++i)
{
free(m_pDatas[i].m_pCompressedData);
m_pDatas[i].m_pCompressedData = 0;
}
io_close(m_File);
m_File = 0;