felipecrv commented on code in PR #41876:
URL: https://github.com/apache/arrow/pull/41876#discussion_r1631571485
##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -1724,9 +1728,9 @@ class ObjectOutputStream final : public io::OutputStream {
RETURN_NOT_OK(EnsureReadyToFlushFromClose());
- auto self =
std::dynamic_pointer_cast<ObjectOutputStream>(shared_from_this());
// Wait for in-progress uploads to finish (if async writes are enabled)
- return FlushAsync().Then([self]() { return
self->FinishPartUploadAfterFlush(); });
+ return FlushAsync().Then(
+ [self = Self()]() { return self->FinishPartUploadAfterFlush(); });
Review Comment:
Rephrasing: it's a good thing that shared_from_this is used here because the
default implementation of `CloseAsync` just copies the naked `this` pointer
into the `std::function` which can lead to UAFs.
> This change is only a small refactor, it changes nothing semantically.
It's a nice one because you elide one ref-count and don't have to generate
code for the destructor of the `self` local variable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]