voiceip/oreka

Possible memory leak in `OggOpusFile.cpp`

Closed this issue · 2 comments

==16187== 6,112 bytes in 8 blocks are definitely lost in loss record 1,975 of 2,023
==16187==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16187==    by 0x582E8B1: comment_pad(char**, int*, int) (OggOpusFile.cpp:41)
==16187==    by 0x58303D8: OggOpusFile::WriteHeader() (OggOpusFile.cpp:396)
==16187==    by 0x5830650: OggOpusFile::Open(CStdStr<char>&, AudioFile::fileOpenModeEnum, bool, int) (OggOpusFile.cpp:206)
==16187==    by 0x57F1335: BatchProcessing::ThreadHandler() (BatchProcessing.cpp:477)
==16187==    by 0x6664C7F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==16187==    by 0x63966B9: start_thread (pthread_create.c:333)
==16187==    by 0x6C4B51C: clone (clone.S:109)

Full output leak.txt

I was looking into possible mem leak and I found in OggOpusFile.cpp->OggOpusFile::WriteHeader():
comment_init() malloc p;
comment_add() realloc p;
comment_pad() realloc p;
At last op.packet = p;
But op.packet wasn't freed after this, so I suspected every time WriteHeader() was called, a new piece of mem chunk for op.packet was allocated.

Thanks @xuxin010033

This was a easy fix and help in huge memory release, since each opus file was leaking some memory.

There is one another leak in ConfigManager.cpp, for which I attempted a solve, but that leads to segfault in another place. Probably you can have a look?