Skip to content

S3CrtClient::GetObjectAsync Doesn't copy handler #1655

@mgraczyk

Description

@mgraczyk

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
The API for the new S3CrtClient::GetObjectAsync function looks like the old API S3Client::GetObjectAsync, but unlike the old API the new one does not copy the handler. This should either be changed or documented because code cannot safely switch from old to new API without potentially hidden bugs.

Example code that is buggy:

void MyFunction() {
  std::string local_thing;
  auto callback = [local_thing](...) {
     ... use local_thing
  };
  s3_crt_client.GetObjectAsync(..., callback, ...);
}

The captured variable local_think could be accessed after its destructor is called because GetObjectAsync takes a pointer rather than a copy of the handler:

userData->userCallback = static_cast<const void*>(&handler);

What's the point of taking std::function as input if the caller still has to manage the lifetime of the handler?

Thanks for reading, let me know if it would be helpful for me to provide additional information.

SDK version number
1.9.22

Platform/OS/Hardware/Device
What are you running the sdk on?
Linux

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code)

Something like the example code.

Expected behavior
Either the difference between new and old API should be documented, or the new API should manage ownership of the handler, or the new API should accept a function pointer instead of std::function

Additional context
The same problem exists with PutObjectAsync, but not with other methods that still like the thread executor (like CompleteMultipartUploadAsync)
Thanks for reading!

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.investigatingThis issue is being investigated and/or work is in progress to resolve the issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions