Skip to content
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 some alloc issue #2

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,49 +668,53 @@ struct aws_s3_meta_request *aws_s3_client_make_meta_request(
struct aws_s3_endpoint *endpoint = NULL;
struct aws_hash_element *endpoint_hash_element = NULL;

int was_created = 0;

if (aws_hash_table_create(
&client->synced_data.endpoints, endpoint_host_name, &endpoint_hash_element, &was_created)) {
// try to support "ip:port", "ip", "hostname:port", "hostname" format
struct aws_array_list raw_endpoint_split;
AWS_ZERO_STRUCT(raw_endpoint_split);
struct aws_byte_cursor raw_endpoint = aws_byte_cursor_from_string(endpoint_host_name);
if (aws_array_list_init_dynamic(
&raw_endpoint_split, client->allocator, 2, sizeof(struct aws_byte_cursor))) {
error_occurred = true;
goto unlock;
}

if (was_created) {
// try to support "ip:port", "ip", "hostname:port", "hostname" format
struct aws_array_list raw_endpoint_split;
AWS_ZERO_STRUCT(raw_endpoint_split);
struct aws_byte_cursor raw_endpoint = aws_byte_cursor_from_string(endpoint_host_name);
if (aws_array_list_init_dynamic(
&raw_endpoint_split, client->allocator, 2, sizeof(struct aws_byte_cursor))) {
error_occurred = true;
goto unlock;
}
if (aws_byte_cursor_split_on_char(&raw_endpoint, ':', &raw_endpoint_split)) {
if (aws_byte_cursor_split_on_char(&raw_endpoint, ':', &raw_endpoint_split)) {
error_occurred = true;
goto unlock;
}
struct aws_byte_cursor raw_host_name;
AWS_ZERO_STRUCT(raw_host_name);
if (aws_array_list_get_at(&raw_endpoint_split, &raw_host_name, 0)) {
error_occurred = true;
goto unlock;
}
struct aws_byte_cursor raw_port;
if (aws_array_list_length(&raw_endpoint_split) == 2) {
// seems we have port?
AWS_ZERO_STRUCT(raw_port);
if (aws_array_list_get_at(&raw_endpoint_split, &raw_port, 1)) {
error_occurred = true;
goto unlock;
}
struct aws_byte_cursor raw_host_name;
AWS_ZERO_STRUCT(raw_host_name);
if (aws_array_list_get_at(&raw_endpoint_split, &raw_host_name, 0)) {
errno = 0;
port = (uint16_t)strtoul((const char *)(raw_port.ptr), NULL, 0);
if (errno != 0) {
error_occurred = true;
goto unlock;
}
struct aws_byte_cursor raw_port;
if (aws_array_list_length(&raw_endpoint_split) == 2) {
// seems we have port?
AWS_ZERO_STRUCT(raw_port);
if (aws_array_list_get_at(&raw_endpoint_split, &raw_port, 1)) {
error_occurred = true;
goto unlock;
}
errno = 0;
port = (uint16_t)strtoul((const char *)(raw_port.ptr), NULL, 0);
if (errno != 0) {
error_occurred = true;
goto unlock;
}
}
}

int was_created = 0;

if (aws_hash_table_create(
&client->synced_data.endpoints,
aws_string_new_from_cursor(client->allocator, &raw_host_name),
&endpoint_hash_element,
&was_created)) {
error_occurred = true;
goto unlock;
}

if (was_created) {

struct aws_s3_endpoint_options endpoint_options = {
.host_name = aws_string_new_from_cursor(client->allocator, &raw_host_name),
Expand Down