1

My intention is to create a relatively simple video playback system to be used in a larger program that I am working on. Relevant code to the video decoder is here. The best I have been able to do so far is narrow down the memory leak to this section of code (or rather I have not noticed any memory leaks occurring when video is not used).

This is probably a very broad question how ever I am unsure of the scope of the issue I am having and as such of how to word my question.

What I want to know is what have I missed or done wrong that has lead to a noticeable memory leak (by noticeable I mean I can watch memory usage climb megabytes per minute). I have tried ensured that every allocation that I make is matched by a deallocation.

EDIT 1
This is to be built on a Windows 10 machine running MSYS2 (MinGW64)

Cethric
  • 101
  • 1
  • 9

1 Answers1

1

Best way to catch a leak is to use in built memory leak checker on compiler, way better than valgrind if you can compile with it.

Add this line to your makefile:

CXXFLAGS += -fno-omit-frame-pointer -fsanitize=address -ggdb3 -O0

If you use old version of gcc (which doesn't support memory sanitizer/checker use clang).

What I know is av_packet_unref may not work as expected if certain conditions not met (you can read more on inside ffmpeg source codes, can't remember the name it was one of the header files talks about these).

After compilation, let memory climb noticeable, then use Ctrl+C to quit. Memory sanitizer will dump the function/line where memory allocated (and not freed later) automatically. If you can't see source code line numbers, use addr2line tool.

Hope that helps.

Lizzy
  • 2,033
  • 3
  • 20
  • 33
the kamilz
  • 1,860
  • 1
  • 15
  • 19
  • I probably should of made this clear when I was asking my question. I am using MinGW64 provided by MSYS2. Can I still do this? – Cethric Jan 03 '18 at 04:40
  • use `gcc -v` on command line it should give gcc version, I think it should have 4.9.x or higher, then you may have a luck. If I'm not mistaken MinGW64 uses windows build of gcc. – the kamilz Jan 03 '18 at 07:39
  • gcc version 7.2.0 (Rev1, Built by MSYS2 project) How ever when I go to build a test file I get the following error D:/MSYS2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lasan – Cethric Jan 04 '18 at 00:38
  • Bad news it seems windows version of gcc doesn't have address sanitizer: https://stackoverflow.com/questions/31144000/mingw-w64s-gcc-and-address-sanitizer – the kamilz Jan 04 '18 at 07:05
  • If your code is portable and not a specific hardware dependant, I'm willing to test your code on my ubuntu linux setup. If that in case gimme a git clone address. – the kamilz Jan 04 '18 at 07:06
  • Unfortunately the code is not easily portable nor do I have a public facing git clone address however I am working on a minimal sample which is just the video player component, which I will forward on once it is ready. I also couldn't find the section of documentation that you referenced. In `avcodec.h` or `avpacket.c`. Thank you for the help – Cethric Jan 05 '18 at 08:46
  • I think it was avformat.h line 175: https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/avformat.h .It says something about duplicating packet and AVPacket.buf. Maybe I did mixed up things but one thing is sure I don't trust `av_packet_unref`. Once to fix memory leak I changed `AVPacket.data` allocations with `av_new_packet` that fixed the problem (a.k.a. `av_packet_unref` worked as it should then). Anyway tell me when your player is ready for test. – the kamilz Jan 05 '18 at 09:00
  • Just pushed a very minimal test program which still shows the memory leak. It can be accessed [here](https://github.com/Cethric/VideoPlayer). It is still a little messy – Cethric Jan 06 '18 at 06:52
  • Ahh. cmake gives some missing CMakeLists.txt error :( – the kamilz Jan 08 '18 at 13:11
  • You will need to do `git submodule update --init` for both VideoPlayer and wxWidgets. I apologise if it is not easy to setup I don't have a *nix based OS setup that can be used to check the CMake setup. – Cethric Jan 09 '18 at 02:19
  • Honestly I couldn't pass this `cmake`. Still gives error. Yes I performed `git submodule update --init` it took a while to download especially `FFmpeg`. Sorry mate :( – the kamilz Jan 10 '18 at 06:47