-
Notifications
You must be signed in to change notification settings - Fork 701
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
fix: missing destructor call in Pistache::Queue #1255
Conversation
include/pistache/mailbox.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tyler92 -
Can you explain a bit more about how this is deallocation is supposed to work?
Of course, directly calling the destructor (as per this change) doesn't of itself free the object being destroyed.
Then again, since res->storage is just a member of Entry, we wouldn't need to deallocate ("operator delete") that.
In popSafe, "entry" was already being deallocated (because we create a std::unique_ptr to it). In pop(), on the other hand, I guess it is up to the caller somehow to deallocate the returned entry.
At the change itself, calling the destructor for the defunct "storage" seems right. Given we've done std::move, though, I wouldn't expect that destructor calling to deallocate any memory (e.g. if there's a pointer to a string in storage, presumably the std::move would already have shifted that pointer elsewhere, leaving nothing for storage to take care of?). I think.
Is there in fact a deallocate that would happen now that wasn't happening before? Or is it simply a matter of ensuring the destructor be called just in case the destructor is performing some needed cleanup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dgreatwood
Given we've done std::move, though, I wouldn't expect that destructor calling to deallocate any memory (e.g. if there's a pointer to a string in storage, presumably the std::move would already have shifted that pointer elsewhere, leaving nothing for storage to take care of?).
Yes, I totally agree, and it works this way for GCC and some versions of Clang. But for some reason, ASAN with Clang 18.1.8 gives this memory leak warning. I'm not sure if it's a false positive or a real issue that's reproduced only with a specific compiler (and maybe even compile flags). I can go deeply and investigate it, but we need to call the destructor anyway, even if it doesn't lead to a memory leak. So...
Is there in fact a deallocate that would happen now that wasn't happening before? Or is it simply a matter of ensuring the destructor be called just in case the destructor is performing some needed cleanup?
... I think it's mostly for correctness, just to avoid potential issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I intentionally made a "wrong" move constructor in unit tests that doesn't clean up the moving object completely. It leads to a memory leak in case of a missing destructor call. Maybe this is not a real case, so please let me know if you think we need to remove it. We have EXPECT_EQ(Data::num_instances, 0);
assertion anyway.
That makes sense.
The change looks good to me.
👍
…On Wed, Oct 16, 2024 at 1:02 PM tyler92 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
On include/pistache/mailbox.h
<#1255 (comment)>:
And I intentionally made a "wrong" move constructor in unit tests that
doesn't clean up the moving object completely. It leads to a memory leak in
case of a missing destructor call. Maybe this is not a real case, so please
let me know if you think we need to remove it. We have EXPECT_EQ(Data::num_instances,
0); assertion anyway.
—
Reply to this email directly, view it on GitHub
<#1255 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFMA236QCXMJLERK6HOKSDZ33A5XAVCNFSM6AAAAABP74DOTOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGNZTGU2TKMRXGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
NOTICE: This email and its attachments may contain privileged and
confidential information, only for the viewing and use of the intended
recipient. If you are not the intended recipient, you are hereby notified
that any disclosure, copying, distribution, acting upon, or use of the
information contained in this email and its attachments is strictly
prohibited and that this email and its attachments must be immediately
returned to the sender and deleted from your system. If you received this
email erroneously, please notify the sender immediately. Xage Security,
Inc. and its affiliates will never request personal information (e.g.,
passwords, Social Security numbers) via email. Report suspicious emails to
***@***.*** ***@***.***>
|
@Tachi107, LGTM. Let us know if you're fine with it. |
version.txt
Outdated
@@ -1 +1 @@ | |||
0.4.8.20241014 | |||
0.4.8.20241015 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyler92, can you bump the patch version? You've changed the internal implementation without changing any public interfaces, so that should normally be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, 0.4.10.20241017
52c24eb
to
a6e6a4f
Compare
a6e6a4f
to
2f4df39
Compare
The
Pistache::Queue
uses placement new which means destructor must be called explicitly but there is one place in the implementation where it's missing. As a result, we might have memory leaks but I got it only with Clang 18.1.8:I also modified the unit test and added one more. Tests output without the fix: