-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing valgrind to detect memory leaks #42
Comments
+1 I agree |
Yes, very good idea. I've been running all of our deps through valgrind and slowing fixing leaks. I don't have valgrind on my normal development machine (OSX and valgrind aren't friends), so the process takes a bit longer than it should. |
Perhaps we could just change this line to |
I have Ubuntu 13.10 machine :). OK, I'll check it out. |
Also, we may have issues failing builds when leaks occur. Valgrind won't change the exit code of the program it's running, even if leaks are detected. Any suggestions / hacks you've used before? |
I think |
I may have been using it wrong, but |
Oops, you're right. I'll investigate it. |
Ah, I misunderstood. |
wait, why isn't this working ? from
|
yay :] |
Ah, okay. We should get the |
Investingating the result and I've found,
|
We may need to test subcommands separately then. Perhaps something like this: valgrind --leak-check=full --error-exitcode=2 ./clib-install foo/bar foo/bar2
EXIT_CODE=$?
[ $EXIT_CODE -eq 2] && {
echo >&2 "Memory leaks detected!";
exit 1
}
[ $EXIT_CODE -eq 0 ] || {
echo >&2 "Test failed for non-memory related reasons";
exit 1
} EDIT: or write our tests in C. |
What do you think of dumping a result to file and grep it to generate error code? |
grepping the results would probably be fine. Can we leave it in the stream rather than writing to file ( |
what would the result dump look like ? |
For example, executing |
Maybe, we can check errors by grepping such a |
I've just fixed a couple leaks (see #43 and #44), but haven't thought of a good way to automate leak checking. Have either of you (@Constellation @jwerle) thought of anything? Looping in @larzconwell, as he's been a great help tracking down and fixing leaks on other projects. |
You can also grep for this line https://gist.github.com/Constellation/d8a25a5c0219740ce7dc#file-dump-log-L127 Also valgrind catches cases where you try to free static or stack memory. The output is a lot different though. |
Hmm so check for successful output rather than errors? That may be a bit more robust. |
Well you can just check if the grep results are empty and go from there. I don't have much else to give, I've haven't tried automating C stuff yet. |
I had a couple ideas on this. One is to build and run the unit tests on OpenBSD with their malloc options turned on full debug. That can shake some bugs out. Another approach is to take over malloc, free, etc and keep track. I found four projects on Github that do this. https://github.com/imsut/malloc-tracer I tried imsut on OSX, since it was the only one that didn't require source code changes. It built fine, but when I ran it there was no log produced. |
Closing due to inactivity. Happy to start a conversation around this again |
In C, memory leaks are major issues of a project.
To detect memory leaks and test it continuously, I suggest introducing a test with valgrind to detect memory leaks in CI.
The text was updated successfully, but these errors were encountered: