Possible memory leak in SDL2-Image? |
No answers? |
Alex
|
No answers? Any ideas how to fix it?
|
|||||||||||
|
Possible memory leak in SDL2-Image? |
Jonas Kulla
Guest
|
If you run valgrind memcheck with the additional parameters "--leak-check=full --show-reachable=yes",
it will show you exactly where these blocks have been allocated. And as the name "still reachable" implies, they aren't lost or leaked by the lib, just likely stored in global variables. For me, all of them originated in dlopen, so it's very likely just the image conversion libraries (libpng, libjpeg) that SDL2_image dlopens at init time and keeps around until either shutdown or IMG_Quit() (which you forgot to call btw.). With IMG_Quit() at the end, the amount of unfreed memory reported by valgrind shrinks to 32 bytes on my end. 2014-10-28 13:10 GMT+01:00 Alex:
|
|||||||||||||
|
Alex
|
Thanks for answer.
And thank you for remind me about IMG_Quit() function. But IMG_Quit() is not helpful in my case. This is the valgrind log after add IMG_Quit() (and IMG_Init too) and with "--leak-check=full --show-reachable=yes" :
As you can see 4096 bytes in 1 block still reachable with IMG_Quit() function too. I try to make my program free from any leaks like this. |
|||||||||||||
|
Possible memory leak in SDL2-Image? |
Jonas Kulla
Guest
|
As you can see in the valgrind log, the allocation originates from libjpeg, so
it is neither an issue with your app nor SDL2_image. If this output bothers you, you can either fix libjpeg, or add a valgrind surpression. 2014-10-28 14:13 GMT+01:00 Alex:
|
|||||||||||||
|
Alex
|
Thanks for information.
I just don't understand why this program used libjpeg if I never use jpeg images. And more: I made init with IMG_Init(IMG_INIT_PNG), to avoid using of libjpeg. But this is not helpful to solve this problem. |
|||||||||||
|
Possible memory leak in SDL2-Image? |
Jonas Kulla
Guest
|
Check the library dependencies of your SDL2_image with
$ readelf -d <your SDL2_image.so> | grep needed you will very likely find a libjpeg in there. If you check the callstack in your valgrind log, you see that the libjpeg init function responsible for the malloc is called by ld.so, ie. the dynamic linker that links all shared libraries at executable startup time, so this is very likely a "library constructor" that is called even before your main function. If you do not want the libjpeg dependency in your application, build SDL2_image with jpeg support disabled. 2014-10-28 16:52 GMT+01:00 Alex:
|
|||||||||||||
|
Possible memory leak in SDL2-Image? |
Jonas Kulla
Guest
|
Oops, that should have been
$ readelf -d <your SDL2_image.so> | grep NEEDED 2014-10-28 17:03 GMT+01:00 Jonas Kulla:
|
|||||||||||||||
|