-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[ASan] Potential leak when running C examples. #1297
Comments
To aid debugging for the
Something weird is going on because the
|
@NikolajBjorner With regards to the
Does the above look like a leak to you? |
At first it did not look like a leak, but let's see:
The particular behavior of C callers in the c_example is that they set a longjump when an error is set inside the API methods. So this could explain the phenomenon: the destructor on the stack allocated ostringstream is not called and therefore the memory on that object is leaked. I have added a commit that calls clear on the buffer object. I haven't reviewed the semantics of clear, but assuming it may free up memory. Could you try it out? |
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
@NikolajBjorner Unfortunately the leak is still reported. Calling You could change the underlying storage by doing
Such a fix seems a bit fragile though. Perhaps the This still doesn't seem like a great fix. Any stack allocated data and clean up might not get called in any of Z3's API functions if the error handler is allowed to use longjmp. In fact I think the other leaks that I've seen (and suppressed) are likely related to this. In these leaks exceptions (look for Perhaps we should document that longjmp should be avoided in error handlers and that its use might leave Z3 in an unspecified state? Then we could change the C API example to not use longjmp. |
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
Thanks, I have to say it makes sense. There are other places that are broken wrt longjump. Other APIs use the error codes. Documentation has not yet been updated. |
@NikolajBjorner Thanks for the fixes. The memory leaks are all gone now :) Would you like me to submit a PR to update Z3's documentation? |
I would say you can hold off for now: I am not sure what is appropriate for the documentation and it may be a fringe thing given that the C-API really should not be used in mainstream. |
…exposed in #1297 Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
As part of my work in PR #1289 I've been running ASan. ASan includes the "LeakSanitizer" which checks for memory leaks on program exit.
The LeakSanitizer currently reports the following leaks when running the C API examples.
I say potential leaks because I don't really understand them.
I believe
_fini
is an automatically generated function that calls various destructors. It seems a string is being allocated that the LeakSanitizer doesn't see deallocated. We don't control this generated code so I'm not sure what's going on here.These two leaks are related. It looks like an exception is being leaked and that leaked exception itself allocates an
std::string
. I don't understand why the exception is being leaked. At a glance (there are rather a lot of macros) it looks like the exception ought to be caught ( I need to double check this though).We are right on the C/C++ boundary in
Z3_mk_iff
so I wonder if there's a bug where Clang doesn't generate the right clean up code.The text was updated successfully, but these errors were encountered: