Skip to content

Commit 9e22700

Browse files
Merge #4986
4986: Free some opengl2 pointers r=Jupeyy a=ChillerDragon Fixes these memory leaks on my system (default opengl 3.0.3 renderer debian 11) ``` Direct leak of 72 byte(s) in 1 object(s) allocated from: #0 0x4eac0d in operator new(unsigned long) (/home/chiller/Desktop/git/ddnet/asan/DDNet+0x4eac0d) #1 0x537ebc in CCommandProcessorFragment_OpenGL2::Cmd_Init(CCommandProcessorFragment_GLBase::SCommand_Init const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1672:21 #2 0x51f4ed in CCommandProcessorFragment_OpenGL::RunCommand(CCommandBuffer::SCommand const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1061:3 #3 0x9e9d5e in CCommandProcessor_SDL_GL::RunBuffer(CCommandBuffer*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:250:20 #4 0x9e57ab in CGraphicsBackend_Threaded::ThreadFunc(void*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:80:25 #5 0x1d49c45 in thread_run(void*) /home/chiller/Desktop/git/ddnet/src/base/system.cpp:867:2 #6 0x7fe2a3b8fea6 in start_thread nptl/pthread_create.c:477:8 Direct leak of 72 byte(s) in 1 object(s) allocated from: #0 0x4eac0d in operator new(unsigned long) (/home/chiller/Desktop/git/ddnet/asan/DDNet+0x4eac0d) #1 0x537ff6 in CCommandProcessorFragment_OpenGL2::Cmd_Init(CCommandProcessorFragment_GLBase::SCommand_Init const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1673:29 #2 0x51f4ed in CCommandProcessorFragment_OpenGL::RunCommand(CCommandBuffer::SCommand const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1061:3 #3 0x9e9d5e in CCommandProcessor_SDL_GL::RunBuffer(CCommandBuffer*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:250:20 #4 0x9e57ab in CGraphicsBackend_Threaded::ThreadFunc(void*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:80:25 #5 0x1d49c45 in thread_run(void*) /home/chiller/Desktop/git/ddnet/src/base/system.cpp:867:2 #6 0x7fe2a3b8fea6 in start_thread nptl/pthread_create.c:477:8 Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x4eac0d in operator new(unsigned long) (/home/chiller/Desktop/git/ddnet/asan/DDNet+0x4eac0d) #1 0x53826a in CCommandProcessorFragment_OpenGL2::Cmd_Init(CCommandProcessorFragment_GLBase::SCommand_Init const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1675:36 #2 0x51f4ed in CCommandProcessorFragment_OpenGL::RunCommand(CCommandBuffer::SCommand const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1061:3 #3 0x9e9d5e in CCommandProcessor_SDL_GL::RunBuffer(CCommandBuffer*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:250:20 #4 0x9e57ab in CGraphicsBackend_Threaded::ThreadFunc(void*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:80:25 #5 0x1d49c45 in thread_run(void*) /home/chiller/Desktop/git/ddnet/src/base/system.cpp:867:2 #6 0x7fe2a3b8fea6 in start_thread nptl/pthread_create.c:477:8 Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x4eac0d in operator new(unsigned long) (/home/chiller/Desktop/git/ddnet/asan/DDNet+0x4eac0d) #1 0x538130 in CCommandProcessorFragment_OpenGL2::Cmd_Init(CCommandProcessorFragment_GLBase::SCommand_Init const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1674:28 #2 0x51f4ed in CCommandProcessorFragment_OpenGL::RunCommand(CCommandBuffer::SCommand const*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend/opengl/backend_opengl.cpp:1061:3 #3 0x9e9d5e in CCommandProcessor_SDL_GL::RunBuffer(CCommandBuffer*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:250:20 #4 0x9e57ab in CGraphicsBackend_Threaded::ThreadFunc(void*) /home/chiller/Desktop/git/ddnet/src/engine/client/backend_sdl.cpp:80:25 #5 0x1d49c45 in thread_run(void*) /home/chiller/Desktop/git/ddnet/src/base/system.cpp:867:2 #6 0x7fe2a3b8fea6 in start_thread nptl/pthread_create.c:477:8 ``` ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: ChillerDrgon <[email protected]>
2 parents 1dea02d + d364c63 commit 9e22700

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/engine/client/backend/opengl/backend_opengl.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,11 @@ bool CCommandProcessorFragment_OpenGL2::Cmd_Init(const SCommand_Init *pCommand)
16351635
if(!CCommandProcessorFragment_OpenGL::Cmd_Init(pCommand))
16361636
return false;
16371637

1638+
m_pTileProgram = nullptr;
1639+
m_pTileProgramTextured = nullptr;
1640+
m_pPrimitive3DProgram = nullptr;
1641+
m_pPrimitive3DProgramTextured = nullptr;
1642+
16381643
m_OpenGLTextureLodBIAS = g_Config.m_GfxGLTextureLODBIAS;
16391644

16401645
m_HasShaders = pCommand->m_pCapabilities->m_ShaderSupport;
@@ -1803,6 +1808,15 @@ bool CCommandProcessorFragment_OpenGL2::Cmd_Init(const SCommand_Init *pCommand)
18031808
return true;
18041809
}
18051810

1811+
void CCommandProcessorFragment_OpenGL2::Cmd_Shutdown(const SCommand_Shutdown *pCommand)
1812+
{
1813+
// TODO: cleanup the OpenGL context too
1814+
delete m_pTileProgram;
1815+
delete m_pTileProgramTextured;
1816+
delete m_pPrimitive3DProgram;
1817+
delete m_pPrimitive3DProgramTextured;
1818+
}
1819+
18061820
void CCommandProcessorFragment_OpenGL2::Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand)
18071821
{
18081822
if(m_HasShaders)

src/engine/client/backend/opengl/backend_opengl.h

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenG
177177

178178
#ifndef BACKEND_GL_MODERN_API
179179
bool Cmd_Init(const SCommand_Init *pCommand) override;
180+
void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override;
180181

181182
void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override;
182183

0 commit comments

Comments
 (0)