-
-
Notifications
You must be signed in to change notification settings - Fork 189
Possible memory leak not detected #169
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
Comments
The Unity test suite doesn't check for memory leaks, so there shouldn't be any warning about that. In this repo we run the tests twice, the second time using |
Right, Unity doesn't support this. CppUTest does support it, but breaks frequently enough with updated toolchains that I would rather not go this route. @patricksjackson what do you think about possibly making |
I think that's a pretty good idea :) Were you thinking about adding it as a separate target in the makefile or adding it to Personally, I think a separate make target might be better. We could document it to the user in the same way that some of the problems have 'Extra Credit' tests. |
I was actually thinking of having it run all the time if it was detected on the system. Is there any downside to having it always run? I have used |
It does slow things down, but for these small tests that should have very few heap allocations it shouldn't slow them down by a lot, maybe 2-3x at the high end. The output can get very chatty and I'd guess is extremely confusing for someone new to a systems language (we could just call it pass/fail like in the CI script, but then there's no way to debug AFAIK). It's also possible that even if valgrind is installed some people would want to try to solve the tests first and then try to do the 'Extra Credit' of fixing the memory leaks, or just not bother trying to solve it that way for a particular problem. |
Makes sense. I'm on board with a second make target. |
I'm adding some tags here and describing what this is looking for: Basically, this thread is saying it would be good to add a new make target to run the tests under Valgrind. With extra credit if you can have it pretty print whether or not there were errors, and re-use the target in A minimal case:
|
I ran valgrind using the parameters in
|
Looks like you're on a Mac, so it's probably this -> https://stackoverflow.com/questions/5226691/valgrind-mac-os-mem-leak First answer has a supposed fix. Valgrind without errors is relatively easy to read, but you may want to run it without the |
To get this moving again I had a little play around with the To begin with I note above that MacOS builds require a suppression file. Following the link Patrick gave I downloaded the latest valgrind and added I've not used valgrind suppressions before, is this the correct way to refer to this file, or is it available as part of the valgrind install somewhere? If correct, is Furthermore I don't have access to test on the Mac platform, if @Gamecock could test if this A)suppresses irrelevant information B) does not suppress relevant information on MacOS, it would be great help 👍 I adjusted the makefile like so, note the additional CFLAGS = -std=c99
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -pedantic
CFLAGS += -Werror
CFLAGS += -O0
CFLAGS += -g
VFLAGS = --quiet
VFLAGS += --suppressions=../../config/darwin16.supp
VFLAGS += --tool=memcheck
VFLAGS += --leak-check=full
VFLAGS += --error-exitcode=1
test: tests.out
@./tests.out
memcheck: tests.out
@valgrind $(VFLAGS) ./tests.out >> /dev/null
clean:
rm -f *.o *.out
tests.out: test/test_hello_world.c src/hello_world.c src/hello_world.h
@echo Compiling $@
@cc $(CFLAGS) src/hello_world.c test/vendor/unity.c test/test_hello_world.c -o tests.out This seems to work for all the playing about that I did with it with the |
Where did you find the darwin16.supp, I looked here and it only has as high as darwin14. Also, don't think config is the right place for suppression file, since students won't get it.needs to be added to something in the exercise folder. Maybe in |
The suppression file is in the valgrind source distribution from the valgrind.org website. I realised the svn2github mirror mentioned in the linked SO question hasn't seen updates in quite some time and that the suppressions don't cover newer versions of MacOS. So I checked to see if there was a more recent version at http://valgrind.org/downloads/current.html 😃 WRT placing the suppression file in each exercise, I had forgotten the students would need access to it as part of the exercise! The vendor file seems logical from the current structure. This does have the downside of needing to change every exercise whenever updating to a newer version though - not sure if that is a concern we need to cover in this case? |
OK, digging into this a little more I have I have |
As regards my earlier question of if this is the correct way of obtaining this file; it seems that pre-built @Gamecock Are you saying that you tried on MacOS, with suppressions, yet still saw those errors? |
Yes, If you install valgrind with brew the darwin16.supp is installed as part of your default. |
There's an article on generating suppressions here: http://kalapun.com/posts/checking-c-code-with-valgrind-on-yosemite/ It might be interesting to see what that spits out for your system @Gamecock However I note that, with the small bit of research I have done this morning, that there has been problems with valgrind on Mac, on and off, for years so it may not be something we can easily solve here. |
I'm leaning to we do not provide a suppression file, just update the README
to say you might need one.
…On Fri, Nov 10, 2017 at 8:27 AM, toby ***@***.***> wrote:
There's an article on generating suppressions here:
http://kalapun.com/posts/checking-c-code-with-valgrind-on-yosemite/
It might be interesting to see what that spits out for your system
@Gamecock <https://github.com/gamecock>
However I note that, with the small bit of research I have done this
morning, that there has been problems with valgrind on Mac, on and off, for
years so it may not be something we can easily solve here.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#169 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFkhSguhH_OntQfkeAbmdWoxtwRv-VS2ks5s1E9XgaJpZM4PZfCq>
.
|
I may have access to a Mac this evening to do some playing about on, but so far your suggestion to leave suppressions up to the user seems like the most sustainable @Gamecock. Seeing as a memory check build is not vital to, nor required for, considering an exercise completed, I'd say that it is a very viable approach too. |
Unfortunately I could not even get Anyway, I say for the sake of ease of maintenance etc, we go with gamecock's idea of not bothering with suppressions for now. I'll raise a PR at some stage this evening for that. |
@toby did you try brew or downloading source and building.
…On Fri, Nov 10, 2017 at 3:18 PM, toby ***@***.***> wrote:
Unfortunately I could not even get valgrind installed on the Mac!
Anyway, I say for the sake of ease of maintenance etc, we go with
gamecock's idea of not bothering with suppressions for now. I'll raise a PR
at some stage this evening for that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#169 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFkhSkQ39XwvcsBL4-i_6r2meyKQMyELks5s1K-wgaJpZM4PZfCq>
.
|
Both. Can't immediately recall why brew didn't work out but it seems that the gcc that was on the machine wasn't suitable for building valgrind according to what I guess if we want to fix the Mac support that could be a future issue/PR? Having Just Windows and Linux support for now is better than the current no-support 😄 . |
I see no reason to not to allow the target for Mac,They should be either
able to modify their default suppression file or alias valgrind to
vallgrind --supress...
…On Fri, Nov 10, 2017 at 3:45 PM, toby ***@***.***> wrote:
Both. Can't immediately recall why brew didn't work out but it seems that
the gcc that was on the machine wasn't suitable for building valgrind
according to what configure.sh reported. I did try to figure out a way
around it but A) my time on the machine was limited (wasn't my rig) and I
was wary of going down the rabbit hole of installing a never ending list of
things just to fix the last thing 😅 , B) I'm so unused to macs (I'm a
life-long windows user and very occasional Linux dabbler) that every new
problem makes things exponentially harder.
I guess if we want to fix the Mac support that could be a future issue/PR?
Having Just Windows and Linux support for now is better than the current
no-support 😄 .
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#169 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFkhSiYjReuO39qZUmLzOzsv1TYRt_OZks5s1LXngaJpZM4PZfCq>
.
|
OK, then. If everyone is OK with adding as in #241 I guess we can go ahead and start raising similar for each exercise. |
#241 has been merged with the following additions to the makefile for CFLAGS += -g
VFLAGS = --quiet
VFLAGS += --tool=memcheck
VFLAGS += --leak-check=full
VFLAGS += --error-exitcode=1
memcheck: tests.out
@valgrind $(VFLAGS) ./tests.out
@echo "Memory check passed" This then needs to be applied to the makefile for every other exercise. As commented in that PR, the |
@wolf99 do you want help with any other exercises or do you got this. Don't want to duplicate any work. |
Thanks, I can work through them in #224 though, it's not much work per exercise. Will need eyes on as I go though, to review for any silly mistakes 🤣 . I plan to do a commit per exercise. |
Closed by #244 |
This issue was raised by byelipk in his exercise. I don't think it applies in that case, but ran again using malloc and no error, I'm not used to Unity yet, but I think there should be one for a malloc without free. Creating the issue until I can dig deeper.
Code I ran to test:
Completely unrelated to the title, but raindrops_test.c needs to be updated to check the value in the buffer, not just the return value. They should match. I can address that at the same time or with a different patch. However you want.
The text was updated successfully, but these errors were encountered: