awslabs / aws-c-s3

C99 library implementation for communicating with the S3 service, designed for maximizing throughput on high bandwidth EC2 instances.
Apache License 2.0
93 stars 37 forks source link

Fix shutdown_callback or returning NULL contract for meta_request #440

Closed waahm7 closed 2 months ago

waahm7 commented 2 months ago

Issue #, if available: https://github.com/aws/aws-sdk-java-v2/issues/5277

Description of changes: There are multiple places where a meta-request can fail after doing the aws_s3_meta_request_init_base like https://github.com/awslabs/aws-c-s3/blob/963949202740da924a4282e79aa43d45e5eaaf31/source/s3_auto_ranged_get.c#L98, https://github.com/awslabs/aws-c-s3/blob/963949202740da924a4282e79aa43d45e5eaaf31/source/s3_client.c#L994, https://github.com/awslabs/aws-c-s3/blob/963949202740da924a4282e79aa43d45e5eaaf31/source/s3_client.c#L1055. In those cases, we were triggering the shutdown callback as well as returning NULL, which is a crime and can lead to double-free errors. This PR moves the shutdown_callback assignment to be the last thing set on the meta_request so that we don’t trigger the shutdown_callback if we fail for any reason after creating the meta_request and before returning it to customers.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.