Skip to content

Commit

Permalink
Merge pull request #2 from opencurve/patch-0809
Browse files Browse the repository at this point in the history
fix some alloc issue
  • Loading branch information
h0hmj authored Aug 9, 2022
2 parents 16cc17d + ceb104e commit 63d288b
Showing 1 changed file with 38 additions and 34 deletions.
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

0 comments on commit 63d288b

Please sign in to comment.