ddnet icon indicating copy to clipboard operation
ddnet copied to clipboard

m_vPending in log.cpp is a memory leak device

Open sjrc6 opened this issue 1 year ago • 5 comments

image

Every chat message leaks 4000bytes

As far as I can tell m_vPending does nothing, but I could be wrong. I could only observe it getting cleared when the game launches and it also doesn't get accessed otherwise.

sjrc6 avatar Apr 26 '24 06:04 sjrc6

Seems like this is the pending log messages for the future file logger, which never get cleared if no logfile is set on client/server side.

As a workaround, you can set a logfile, which should prevent the leak.

Robyt3 avatar Apr 26 '24 16:04 Robyt3

If I set a log file then wouldn't it fill up my hard drive with the messages instead of my ram?

sjrc6 avatar Apr 26 '24 18:04 sjrc6

If I set a log file then wouldn't it fill up my hard drive with the messages instead of my ram?

Yes, but more slowly because it wouldn't allocate 4 KiB for every log message but only write as many bytes as the messages contain.

Robyt3 avatar Apr 26 '24 19:04 Robyt3

For me this isn't a viable solution. I've just removed m_vPending from my build for now. The chat system can handle billions of messages no problem without this logging code.

sjrc6 avatar Apr 26 '24 22:04 sjrc6

Alternatively as a workaround you could try setting /dev/null as a log file, but then its still doing unnecessary work. Not logging to file shouldn't leak memory tho.

hardliner66 avatar Apr 28 '24 10:04 hardliner66