-
Notifications
You must be signed in to change notification settings - Fork 480
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
Double free #790
Comments
In your code I don't see that any instance of CpuPower/SystemCounterState was ever created.
This allocation is here: Line 139 in 38aaf6c
Not really related to SystemCounterState Could be a valgrind issue? |
Yes. Because even an object of this class has not been created. I tried to uncomment other attributes and comment Probably this is happening in some PCM finalization code that is called when the library is unloaded?
Definitely not, because I see double free without Valgrind. Stack:
Compiler: gcc-14.1.1, C++17. |
Aha, got it! utils.cpp:128: std::vector<const char *> colorTable = {
ASCII_GREEN,
ASCII_YELLOW,
ASCII_MAGENTA,
ASCII_CYAN,
ASCII_BRIGHT_GREEN,
ASCII_BRIGHT_YELLOW,
ASCII_BRIGHT_BLUE,
ASCII_BRIGHT_MAGENTA,
ASCII_BRIGHT_CYAN,
ASCII_BRIGHT_WHITE
}; Problem happened, when the vector destructor called. |
It can be fixed by replacing vector with array: constexpr static std::array<const char *, 10> colorTable = {
ASCII_GREEN,
ASCII_YELLOW,
ASCII_MAGENTA,
ASCII_CYAN,
ASCII_BRIGHT_GREEN,
ASCII_BRIGHT_YELLOW,
ASCII_BRIGHT_BLUE,
ASCII_BRIGHT_MAGENTA,
ASCII_BRIGHT_CYAN,
ASCII_BRIGHT_WHITE
}; |
thanks for the valgrind W/A.
Unfortunately I still don't see why colorTable destructor needs to be called twice by __run_exit_handlers. What is wrong in having static std::vector arrays? |
See above. |
I thought ASCII_GREEN itself is not allocated on the heap. It is a constexpr already
And no delete should be called for it. Only for the std vector array that holds the pointers to those constexpr char *. Does it also report a leak if you put a vector with a different type (int instead of char *): std::vector intTable = {1,2,3,4,5,6,7,8,9,10}; |
Yes.
Yes.
Because this container is constexpr, but the vector is not and frees memory (from .rodata?) in runtime.
This is not a leak, this is a double free: deallocating already deallocated memory. Strictly speaking, a vector does not free memory. As a fact: with constexpr array the double free problem was gone. |
thanks.. I meant double-free, not a leak. As a developer one can expect that if one writes something like that: Anyway, if you have more time a pull request would be welcome. |
With vector probably my explanation is not correct. My idea was that the line is deleted in runtime, and then automatically when the application is unloaded. This did not happen with |
Yes, probably, you're right. Strings will not be deleted by the pointer. It's my failure. |
But double-free exists somewhere here. |
I have a class to get power, consuming by core:
All code in methods are commented, all attributes, except
sstates
are commented.This class is a part of the library, statically linked to the bare gtest tester.
Tester code:
Running tester gives double free:
After commenting sstates (even if other attributes are uncommented), all works:
This error exists only on Linux, not on Windows.
Valgrind output:
This problem doesn't exist in PCM 202403.
The text was updated successfully, but these errors were encountered: