From 1081a6870c068afbe61fe03f2c51dc2b59c07a77 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 18 Oct 2020 12:53:21 +0200 Subject: [PATCH] Put CLineReader on stack so we can't forget to delete it Found in https://github.com/ddnet/ddnet/issues/3134 Direct leak of 360712 byte(s) in 11 object(s) allocated from: #0 0x51fb22 in operator new(unsigned long) (/home/teeworlds/servers/DDNet-Server-asan+0x51fb22) #1 0x561d77 in CServer::GetAnnouncementLine(char const*) /home/teeworlds/src/master/src/engine/server/server.cpp:3563:20 #2 0x5c00a7 in CGameContext::OnTick() /home/teeworlds/src/master/src/game/server/gamecontext.cpp:971:32 #3 0x556073 in CServer::Run() /home/teeworlds/src/master/src/engine/server/server.cpp:2544:19 #4 0x561a56 in main /home/teeworlds/src/master/src/engine/server/server.cpp:3537:21 #5 0x7f2349f3809a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a) --- src/engine/server/server.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 0a33c08f1..2af4fd3a4 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -3560,9 +3560,9 @@ const char *CServer::GetAnnouncementLine(char const *pFileName) std::vector v; char *pLine; - CLineReader *lr = new CLineReader(); - lr->Init(File); - while((pLine = lr->Get())) + CLineReader lr; + lr.Init(File); + while((pLine = lr.Get())) if(str_length(pLine)) if(pLine[0] != '#') v.push_back(pLine);