-
Notifications
You must be signed in to change notification settings - Fork 57
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
Temporary values are not destructed in C, e.g. string interpolation leaks memory #26
Comments
All tests are run in Travis CI. C, C++ and Swift tests are run with the Address Sanitizer and There's this line in the C translation of
Why do you think it leaks memory? |
I'm sorry, I misread the example. Here is a simpler one:
gets compiled to
There is no |
Yes, it's a known issue. I've just added a test and will fix it. Interpolated strings are even worse when targetting C++, because they use C++20 |
I believe the problem also exists with dynamic references in general. E.g. the following code:
leaks memory and does not induce the |
|
FWIW, I just learned that smart pointers are possible in C with GNU compilers: https://stackoverflow.com/questions/799825/smart-pointers-safe-memory-management-for-c |
@Timerix22 af1f308 fixes the concatenation of multiple strings. I will work on the remaining cases. |
All cases reported here are now fixed. |
Consider
OpAddAssignString.ci
:gets compiled to
here, the result of
CiString_Format
is a result ofmalloc
. It's passed toCiString_Assign
and abandoned afterwards, leaking memory. This does not happen in C++ because temporary values are automatically destructed in C++, includingstd::string
.I assume there may be other instances where temporary objects are created and not immediately stored into variables.
The text was updated successfully, but these errors were encountered: