Problems with valgrind and SDL
by Linus Probert
So, I’m working on my new game. I want to be thorough and make sure I didn’t accidentally introduce any nasty leaks or memory errors. I startup the old trusty valgrind and it spits out over nine thousand different errors regarding leaks and bad jumps. I figure, I’m not the god of code, but I’m sure as hell not that bad. Especially not bad enough to make roughly 1000+ loc cause that many errors.
Now, if you have any experience with SDL 1 or 2 and valgrind. This problem shouldn’t come as a surprise to you. Different graphics drivers and various other libraries that SDL makes use of sometimes can contain errors in them that don’t actually harm the execution of your game but can still make valgrind freak out.
Now up until this point the errors have been so few that I’ve happily been able to ignore them and easily visually filter out the problems that are cause by my code. However my new fancy laptop with intel HiDPI fancy graphics wasn’t being as nice to me. There was a literal wall of crap spewing from valgrind just from the initSDL call at the beginning of my game.
So this needed some looking into. It took me about 2 minutes of googling to find a solution to my problem. “Valgrind suppression’s”, you should google that too if you’re having similar issues or just generally want to clean up your valgrind output.
I essentially did the following:
This will produce a logfile of the regular valgrind error output but after each “problem” there will also be a structure similar to json which is a format for supressing that particular error.
Based on that data you should be able to create something like this:
Which should significantly reduce the amount of spam from your valgrind tests.
You might even store this data in files somewhere useful and create a ‘.valgrindrc’ file in your $HOME directory such as this:
And then everything should look nice in the future. :)
Now, my files might not be perfect. Google around if something seems wonky and perhaps even get back to me with feedback. I didn’t become a valgrind expert in order to make this post. I just stumbled upon it because I was having a problem and I thought I’d share it with… the internet and the google spiders.
// Liq
tags: sdl2 - sdl - valgrind - c - c++