Skip to content

Commit

Permalink
Move code around to get rid of early_fail
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Oct 15, 2024
1 parent 5d22320 commit 3f43e21
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,6 @@ struct aws_s3_client *aws_s3_client_new(
}
}

if (aws_mutex_init(&client->synced_data.lock) != AWS_OP_SUCCESS) {
goto on_early_fail;
}

client->buffer_pool = aws_s3_buffer_pool_new(allocator, part_size, mem_limit);

if (client->buffer_pool == NULL) {
goto on_early_fail;
}

struct aws_s3_buffer_pool_usage_stats pool_usage = aws_s3_buffer_pool_get_usage(client->buffer_pool);

if (client_config->max_part_size > pool_usage.mem_limit) {
aws_s3_buffer_pool_destroy(client->buffer_pool);
AWS_LOGF_ERROR(
AWS_LS_S3_CLIENT,
"Cannot create client from client_config; configured max part size should not exceed memory limit."
"size.");
aws_raise_error(AWS_ERROR_S3_INVALID_MEMORY_LIMIT_CONFIG);
goto on_early_fail;
}

client->vtable = &s_s3_client_default_vtable;

aws_ref_count_init(&client->ref_count, client, (aws_simple_completion_callback *)s_s3_client_start_destroy);
Expand Down Expand Up @@ -405,10 +383,6 @@ struct aws_s3_client *aws_s3_client_new(
*((uint64_t *)&client->max_part_size) = s_default_max_part_size;
}

if (client_config->max_part_size > pool_usage.mem_limit) {
*((uint64_t *)&client->max_part_size) = pool_usage.mem_limit;
}

if (client->max_part_size > SIZE_MAX) {
/* For the 32bit max part size to be SIZE_MAX */
*((uint64_t *)&client->max_part_size) = SIZE_MAX;
Expand Down Expand Up @@ -489,6 +463,30 @@ struct aws_s3_client *aws_s3_client_new(
}
}

if (aws_mutex_init(&client->synced_data.lock) != AWS_OP_SUCCESS) {
goto on_error;
}

client->buffer_pool = aws_s3_buffer_pool_new(allocator, part_size, mem_limit);

if (client->buffer_pool == NULL) {
goto on_error;
}

struct aws_s3_buffer_pool_usage_stats pool_usage = aws_s3_buffer_pool_get_usage(client->buffer_pool);

if (client_config->max_part_size > pool_usage.mem_limit) {
AWS_LOGF_ERROR(
AWS_LS_S3_CLIENT,
"Cannot create client from client_config; configured max part size should not exceed memory limit."
"size.");
aws_raise_error(AWS_ERROR_S3_INVALID_MEMORY_LIMIT_CONFIG);
goto on_error;
}
if (client_config->max_part_size > pool_usage.mem_limit) {
*((uint64_t *)&client->max_part_size) = pool_usage.mem_limit;
}

client->num_network_interface_names = client_config->num_network_interface_names;
if (client_config->num_network_interface_names > 0) {
AWS_LOGF_DEBUG(
Expand Down Expand Up @@ -653,7 +651,6 @@ struct aws_s3_client *aws_s3_client_new(
aws_array_list_clean_up(&client->network_interface_names);
aws_s3_buffer_pool_destroy(client->buffer_pool);

on_early_fail:
aws_mem_release(client->allocator, client);
return NULL;
}
Expand Down

0 comments on commit 3f43e21

Please sign in to comment.