-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Bug]: valgrind reports still reachable memory leaks when StrictMock or NiceMock are used #4109
Comments
I got the same. I am using from sources, so I was able to git bisect that problematic commit is 0320f51. Valgrind error no longer reported for me if I revert this commit from current main branch latest. |
If I understand correctly, this appears to be due to the change to Would you mind clarifying if the "leakage" is actually causing an execution problem for you somehow, or whether you are simply trying to reduce the noise? If it is the former, please let us know how you are running into the issue (a repro would be very helpful). If it's the latter, then unfortunately we may leave the state as-is. For context: one reason to lazy-initialize variables like this is the static initialization order fiasco. Unfortunately, while construction can be deferred to occur lazily, the same thing cannot be said for destructors, which suffer from the same problems. Thus ensuring safe tear-down can be difficult if note impossible to ensure, and often the fix is to simply let the variables persist until the process is torn down. |
Before the change Tero pointed out, valgrind didn't report any problems within gtest or gmock. After that change, it does. I would not classify this issue as "trying to reduce the noise". It is also not causing an "execution problem" I'm aware of. If you decide to do nothing about this, anyone that runs a gtest/gmock based unit test under valgrind that uses StrictMock or NiceMock and wants to have a clean bill of health will have to expend effort investigating these leaks and eventually devise and implement their own mitigation (valgrind suppression, gmock hack, lock into gtest/gmock version 1.11.0, etc). It looks like Tero and I aren't the only people who have tripped over this so far as that commit has an unanswered question about the justification for introduction of a memory leak from someone else. I went back to gtest/gmock 1.11.0 to hastily avoid this problem. Building it and my unit test using GCC 12.2.0 with -Wall (which turns on -Wmaybe-uninitialized) does not produce the uninitialized warning that lead to the change that caused this issue. So, minimally, it may be worthwhile to determine if the problem that lead to that change is still relevant. |
This has nothing to do with "reducing noise". Noise is really bad when it comes to automated testing. This is actually about the definition of a leak. One definition of a leak is that every The definition these leak checkers are using by default is something like "it is a leak if there is no live pointer variable that points to the allocation". In the commit in question, at shutdown, a static pointer still points to the memory. If, for example, there were a second We understand that there are some that prefer the draconian definition of a leak. We disagree and our experience has been that the draconian definition simply isn't useful. C++'s well-known undefined initialization and destruction ordering issues cause far more issues. This is why we don't support draconian leak checking. |
Some Mock constructors insert the pointer to the Mock itself into a global registry. Since GCC cannot see how the pointer is used (only as an identifier), it cannot tell that the object doesn't need to be initialized at that point at all. Work around this by using uintptr_t instead. PiperOrigin-RevId: 452380347 Change-Id: Ia5a493057ed90719de1d0efab71de9a8a08ddf8b
Describe the issue
Valgrind reports still reachable memory leaks when StrictMock or NiceMock are used. This didn't happen in gtest/gmock 1.11.0.
Steps to reproduce the problem
g++ -g gmock_leak.cpp -lgtest -lgmock -lgmock_main
):valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ./a.out
)What version of GoogleTest are you using?
1.12.1
What operating system and version are you using?
debian testing (aka 12, aka bookworm)
What compiler and version are you using?
The text was updated successfully, but these errors were encountered: