Skip to content
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

Update unity_fixture.c #205

Merged
merged 3 commits into from
Aug 2, 2016
Merged

Conversation

bryonglodencissp
Copy link
Contributor

[../Unity-master/extras/fixture/src/unity_fixture.c:210]: (error) Memory leak: guard

Found by https://github.com/bryongloden/cppcheck
@mvandervoord
Copy link
Member

This submission fails the automated self-tests. I suspect it's because it is only valid #ifndef UNITY_EXCLUDE_STDLIB_MALLOC?

@bryonglodencissp
Copy link
Contributor Author

bryonglodencissp commented Jul 26, 2016

Nope! My tool is reporting the error when no tokens have been defined (but not when UNITY_EXCLUDE_STDLIB_MALLOC is defined) i.e.

Checking ../Unity-master/extras/fixture/src/unity_fixture.c...
[../Unity-master/extras/fixture/src/unity_fixture.c:210]: (error) Memory leak: guard
Checking ../Unity-master/extras/fixture/src/unity_fixture.c: UNITY_EXCLUDE_STDLIB_MALLOC...
19/47 files checked 17% done

I suspect the error is related to the command "make -s default noStdlibMalloc" exited with 2. But because I'm unfamiliar with this command, do I close the PR?

@bryonglodencissp
Copy link
Contributor Author

bryonglodencissp commented Jul 26, 2016

LOL. I believe you now @mvandervoord! It's related to UNITY_EXCLUDE_STDLIB_MALLOC 😁. The answer was just hidden inside the Makefile.

Free guard if UNITY_EXCLUDE_STDLIB_MALLOC is not defined. 👍

Thanks @ for the hint.
@bryonglodencissp
Copy link
Contributor Author

Hi @mvandervoord ! I believe I edited unity_fixture.c correctly in 0737b41 (by including #ifndef around my patch code). However, the new submission failed the automated self-tests for presumably the same reason. Any more hints before I close this and #206?

@mvandervoord
Copy link
Member

It seems like it is disagreeing with your change altogether. The error you are getting at this point is "*** glibc detected *** build/framework_test.exe: double free or corruption (fasttop): 0x0000000001444010 **"... I *think this happens when release_memory is called, because you are now removing the guard object before then.

Why is it that you thought this was necessary? What situation are you covering for?

@bryonglodencissp
Copy link
Contributor Author

bryonglodencissp commented Jul 26, 2016

Hi @mvandervoord. Thank you for looking over this. We've done studies you know; 60% of the time cppcheck works all the time 👍.

Here we think it's necessary to free() memory because we believe its output. And here Steve Jessop enumerates the lists of situations we're 'covering' for (he even includes some situations we're not covering for 👍).

If you want/need a specific answer detailing the reasons our program detected an error in your code, then I suspect it'll have to wait until after dinner (at the very least 👍).

Although, if you're confident in your implementation of memory management, then just close this and PR #206 and chalk it all up as volunteerism 😁

@mvandervoord
Copy link
Member

I believe your tool has identified a problem as I look through this... I think your solution is wrong, though. I could be mistaken (this isn't actually my code... this file is an addon submitted by a third party. It's used by roughly a quarter of the Unity users, though, so I'd love to fix it up).

Anyway, your solution frees the memory before it's even called upon to be used. That's why you're running into an error about double-freeing memory.

In the most common case, I think the current system works. Memory is allocated in unity_malloc and it is freed again in unity_free. However, part of the point of this subsystem is to catch errors that people make, like not calling free when they should... and now that I am staring at it, I don't actually SEE a place where it checks to see if anyone ever came back and cleared that memory!

I think this is probably intended to happen somewhere in UnityConcludeFixtureTest?

Let me know what you think after dinner. ;)

Sorry @mvandervoord -- not your code, your repository 😁

Regarding the double free, cppcheck has a check for that too (just saying) 👍
@bryonglodencissp
Copy link
Contributor Author

Commits b1d8388 and 0737b41 fixed with 4fd5f79, thank you @mvandervoord

@mvandervoord mvandervoord merged commit 783fcae into ThrowTheSwitch:master Aug 2, 2016
@jsalling
Copy link
Contributor

Oops. This tool is suggesting to free guard, but it should never be freed during unity_malloc.
The guard has the job of, well, guarding the malloc'd memory passed to the caller. It's also how the implementation frees the total memory.

I'm going to revert this commit in another PR. The preprocessor conditional is never going to be true, so this is dead code, which is why it works.

Quote:

However, part of the point of this subsystem is to catch errors that people make, like not calling free when they should... and now that I am staring at it, I don't actually SEE a place where it checks to see if anyone ever came back and cleared that memory!
I think this is probably intended to happen somewhere in UnityConcludeFixtureTest?

@mvandervoord This happens in the UnityTestRunner. Each test that uses this part of the fixture must free for each malloc, calloc, or realloc.

jsalling added a commit to jsalling/Unity that referenced this pull request Aug 21, 2016
 This reverts commit 783fcae
 The guard memory bytes should never be freed inside unity_malloc()
@bryonglodencissp
Copy link
Contributor Author

Yes, unfortunately, sound and complete static analysis is shown to be undecidable. We're led to this false positive because we've adopted some unsound techniques in our tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants