@@ -346,7 +346,7 @@ struct aws_s3_client *aws_s3_client_new(
346346 client -> buffer_pool = aws_s3_buffer_pool_new (allocator , part_size , mem_limit );
347347
348348 if (client -> buffer_pool == NULL ) {
349- goto on_early_fail ;
349+ goto on_error ;
350350 }
351351
352352 struct aws_s3_buffer_pool_usage_stats pool_usage = aws_s3_buffer_pool_get_usage (client -> buffer_pool );
@@ -357,15 +357,15 @@ struct aws_s3_client *aws_s3_client_new(
357357 "Cannot create client from client_config; configured max part size should not exceed memory limit."
358358 "size." );
359359 aws_raise_error (AWS_ERROR_S3_INVALID_MEMORY_LIMIT_CONFIG );
360- goto on_early_fail ;
360+ goto on_error ;
361361 }
362362
363363 client -> vtable = & s_s3_client_default_vtable ;
364364
365365 aws_ref_count_init (& client -> ref_count , client , (aws_simple_completion_callback * )s_s3_client_start_destroy );
366366
367367 if (aws_mutex_init (& client -> synced_data .lock ) != AWS_OP_SUCCESS ) {
368- goto on_early_fail ;
368+ goto on_error ;
369369 }
370370
371371 aws_linked_list_init (& client -> synced_data .pending_meta_request_work );
@@ -488,6 +488,44 @@ struct aws_s3_client *aws_s3_client_new(
488488 }
489489 }
490490
491+ client -> num_network_interface_names = client_config -> num_network_interface_names ;
492+ if (client_config -> num_network_interface_names > 0 ) {
493+ AWS_LOGF_DEBUG (
494+ AWS_LS_S3_CLIENT ,
495+ "id=%p Client received network interface names array with length %zu." ,
496+ (void * )client ,
497+ client -> num_network_interface_names );
498+ aws_array_list_init_dynamic (
499+ & client -> network_interface_names ,
500+ client -> allocator ,
501+ client_config -> num_network_interface_names ,
502+ sizeof (struct aws_string * ));
503+ client -> network_interface_names_cursor_array = aws_mem_calloc (
504+ client -> allocator , client_config -> num_network_interface_names , sizeof (struct aws_byte_cursor ));
505+ for (size_t i = 0 ; i < client_config -> num_network_interface_names ; i ++ ) {
506+ struct aws_byte_cursor interface_name = client_config -> network_interface_names_array [i ];
507+ struct aws_string * interface_name_str = aws_string_new_from_cursor (client -> allocator , & interface_name );
508+ aws_array_list_push_back (& client -> network_interface_names , & interface_name_str );
509+ if (aws_is_network_interface_name_valid (aws_string_c_str (interface_name_str )) == false) {
510+ AWS_LOGF_ERROR (
511+ AWS_LS_S3_CLIENT ,
512+ "id=%p network_interface_names_array[%zu]=" PRInSTR " is not valid." ,
513+ (void * )client ,
514+ i ,
515+ AWS_BYTE_CURSOR_PRI (interface_name ));
516+ aws_raise_error (AWS_ERROR_INVALID_ARGUMENT );
517+ goto on_error ;
518+ }
519+ client -> network_interface_names_cursor_array [i ] = aws_byte_cursor_from_string (interface_name_str );
520+ AWS_LOGF_DEBUG (
521+ AWS_LS_S3_CLIENT ,
522+ "id=%p network_interface_names_array[%zu]=" PRInSTR "" ,
523+ (void * )client ,
524+ i ,
525+ AWS_BYTE_CURSOR_PRI (client -> network_interface_names_cursor_array [i ]));
526+ }
527+ }
528+
491529 /* Set up body streaming ELG */
492530 {
493531 uint16_t num_event_loops =
@@ -579,34 +617,6 @@ struct aws_s3_client *aws_s3_client_new(
579617 * ((bool * )& client -> enable_read_backpressure ) = client_config -> enable_read_backpressure ;
580618 * ((size_t * )& client -> initial_read_window ) = client_config -> initial_read_window ;
581619
582- client -> num_network_interface_names = client_config -> num_network_interface_names ;
583- if (client_config -> num_network_interface_names > 0 ) {
584- AWS_LOGF_DEBUG (
585- AWS_LS_S3_CLIENT ,
586- "id=%p Client received network interface names array with length %zu." ,
587- (void * )client ,
588- client -> num_network_interface_names );
589- aws_array_list_init_dynamic (
590- & client -> network_interface_names ,
591- client -> allocator ,
592- client_config -> num_network_interface_names ,
593- sizeof (struct aws_string * ));
594- client -> network_interface_names_cursor_array = aws_mem_calloc (
595- client -> allocator , client_config -> num_network_interface_names , sizeof (struct aws_byte_cursor ));
596- for (size_t i = 0 ; i < client_config -> num_network_interface_names ; i ++ ) {
597- struct aws_byte_cursor interface_name = client_config -> network_interface_names_array [i ];
598- struct aws_string * interface_name_str = aws_string_new_from_cursor (client -> allocator , & interface_name );
599- aws_array_list_push_back (& client -> network_interface_names , & interface_name_str );
600- client -> network_interface_names_cursor_array [i ] = aws_byte_cursor_from_string (interface_name_str );
601- AWS_LOGF_DEBUG (
602- AWS_LS_S3_CLIENT ,
603- "id=%p network_interface_names_array[%zu]=" PRInSTR "" ,
604- (void * )client ,
605- i ,
606- AWS_BYTE_CURSOR_PRI (client -> network_interface_names_cursor_array [i ]));
607- }
608- }
609-
610620 return client ;
611621
612622on_error :
@@ -628,10 +638,22 @@ struct aws_s3_client *aws_s3_client_new(
628638 aws_mem_release (client -> allocator , client -> proxy_ev_settings );
629639 aws_mem_release (client -> allocator , client -> tcp_keep_alive_options );
630640
631- aws_event_loop_group_release (client -> client_bootstrap -> event_loop_group );
641+ if (client -> client_bootstrap != NULL ) {
642+ aws_event_loop_group_release (client -> client_bootstrap -> event_loop_group );
643+ }
632644 aws_client_bootstrap_release (client -> client_bootstrap );
633645 aws_mutex_clean_up (& client -> synced_data .lock );
634- on_early_fail :
646+
647+ aws_mem_release (client -> allocator , client -> network_interface_names_cursor_array );
648+ for (size_t i = 0 ; i < aws_array_list_length (& client -> network_interface_names ); i ++ ) {
649+ struct aws_string * interface_name = NULL ;
650+ aws_array_list_get_at (& client -> network_interface_names , & interface_name , i );
651+ aws_string_destroy (interface_name );
652+ }
653+
654+ aws_array_list_clean_up (& client -> network_interface_names );
655+ aws_s3_buffer_pool_destroy (client -> buffer_pool );
656+
635657 aws_mem_release (client -> allocator , client );
636658 return NULL ;
637659}
0 commit comments