diff --git a/source/aws_imds_client.c b/source/aws_imds_client.c index 5ea2b801..281b7ec4 100644 --- a/source/aws_imds_client.c +++ b/source/aws_imds_client.c @@ -124,10 +124,6 @@ struct aws_imds_client *aws_imds_client_new( } struct aws_imds_client *client = aws_mem_calloc(allocator, 1, sizeof(struct aws_imds_client)); - if (!client) { - return NULL; - } - if (aws_mutex_init(&client->token_lock)) { goto on_error; } diff --git a/source/aws_signing.c b/source/aws_signing.c index fe5610e2..d99f6059 100644 --- a/source/aws_signing.c +++ b/source/aws_signing.c @@ -339,9 +339,6 @@ struct aws_signing_state_aws *aws_signing_state_new( } struct aws_signing_state_aws *state = aws_mem_calloc(allocator, 1, sizeof(struct aws_signing_state_aws)); - if (!state) { - return NULL; - } state->allocator = allocator; diff --git a/source/credentials.c b/source/credentials.c index 3340663d..d48c8246 100644 --- a/source/credentials.c +++ b/source/credentials.c @@ -103,9 +103,6 @@ struct aws_credentials *aws_credentials_new( } struct aws_credentials *credentials = aws_mem_acquire(allocator, sizeof(struct aws_credentials)); - if (credentials == NULL) { - return NULL; - } AWS_ZERO_STRUCT(*credentials); @@ -316,9 +313,6 @@ struct aws_credentials *aws_credentials_new_ecc( } struct aws_credentials *credentials = aws_mem_calloc(allocator, 1, sizeof(struct aws_credentials)); - if (credentials == NULL) { - return NULL; - } credentials->allocator = allocator; credentials->expiration_timepoint_seconds = expiration_timepoint_in_seconds; diff --git a/source/credentials_provider_anonymous.c b/source/credentials_provider_anonymous.c index 62a9a659..3099ba5b 100644 --- a/source/credentials_provider_anonymous.c +++ b/source/credentials_provider_anonymous.c @@ -42,9 +42,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_anonymous( struct aws_credentials_provider *provider = aws_mem_calloc(allocator, 1, sizeof(struct aws_credentials_provider)); struct aws_credentials *credentials = aws_credentials_new_anonymous(allocator); - if (credentials == NULL) { - goto on_new_credentials_failure; - } aws_credentials_provider_init_base(provider, allocator, &s_aws_credentials_provider_anonymous_vtable, credentials); @@ -53,10 +50,4 @@ struct aws_credentials_provider *aws_credentials_provider_new_anonymous( } return provider; - -on_new_credentials_failure: - - aws_mem_release(allocator, provider); - - return NULL; } diff --git a/source/credentials_provider_cached.c b/source/credentials_provider_cached.c index 300794f1..eb24b99a 100644 --- a/source/credentials_provider_cached.c +++ b/source/credentials_provider_cached.c @@ -256,10 +256,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_cached( &impl, sizeof(struct aws_credentials_provider_cached)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_chain.c b/source/credentials_provider_chain.c index b93e708c..adf19abc 100644 --- a/source/credentials_provider_chain.c +++ b/source/credentials_provider_chain.c @@ -146,6 +146,7 @@ struct aws_credentials_provider *aws_credentials_provider_new_chain( const struct aws_credentials_provider_chain_options *options) { if (options->provider_count == 0) { + aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); return NULL; } @@ -160,10 +161,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_chain( &impl, sizeof(struct aws_credentials_provider_chain_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_cognito.c b/source/credentials_provider_cognito.c index ece91b8a..6a9b7e36 100644 --- a/source/credentials_provider_cognito.c +++ b/source/credentials_provider_cognito.c @@ -699,10 +699,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_cognito( &impl, sizeof(struct aws_credentials_provider_cognito_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_default_chain.c b/source/credentials_provider_default_chain.c index 260784f4..2642911d 100644 --- a/source/credentials_provider_default_chain.c +++ b/source/credentials_provider_default_chain.c @@ -134,9 +134,7 @@ static struct default_chain_callback_data *s_create_callback_data( void *user_data) { struct default_chain_callback_data *callback_data = aws_mem_calloc(provider->allocator, 1, sizeof(struct default_chain_callback_data)); - if (callback_data == NULL) { - return NULL; - } + callback_data->allocator = provider->allocator; callback_data->default_chain_provider = provider; callback_data->original_callback = callback; @@ -257,10 +255,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_chain_default( &impl, sizeof(struct aws_credentials_provider_default_chain_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_delegate.c b/source/credentials_provider_delegate.c index 63cd6696..bdc10009 100644 --- a/source/credentials_provider_delegate.c +++ b/source/credentials_provider_delegate.c @@ -47,10 +47,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_delegate( &impl, sizeof(struct aws_credentials_provider_delegate_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_ecs.c b/source/credentials_provider_ecs.c index 7d96cf3a..4bcf8c07 100644 --- a/source/credentials_provider_ecs.c +++ b/source/credentials_provider_ecs.c @@ -502,11 +502,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_ecs( sizeof(struct aws_credentials_provider), &impl, sizeof(struct aws_credentials_provider_ecs_impl)); - - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_environment.c b/source/credentials_provider_environment.c index 791e7e2b..9426caec 100644 --- a/source/credentials_provider_environment.c +++ b/source/credentials_provider_environment.c @@ -65,9 +65,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_environment( struct aws_allocator *allocator, const struct aws_credentials_provider_environment_options *options) { struct aws_credentials_provider *provider = aws_mem_acquire(allocator, sizeof(struct aws_credentials_provider)); - if (provider == NULL) { - return NULL; - } AWS_ZERO_STRUCT(*provider); diff --git a/source/credentials_provider_imds.c b/source/credentials_provider_imds.c index 3d5e71f6..31d6cf97 100644 --- a/source/credentials_provider_imds.c +++ b/source/credentials_provider_imds.c @@ -71,10 +71,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_imds( &impl, sizeof(struct aws_credentials_provider_imds_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); @@ -133,9 +129,7 @@ static struct imds_provider_user_data *s_imds_provider_user_data_new( struct imds_provider_user_data *wrapped_user_data = aws_mem_calloc(imds_provider->allocator, 1, sizeof(struct imds_provider_user_data)); - if (wrapped_user_data == NULL) { - goto on_error; - } + if (aws_byte_buf_init(&wrapped_user_data->role, imds_provider->allocator, 100)) { goto on_error; } diff --git a/source/credentials_provider_process.c b/source/credentials_provider_process.c index d043ff39..79467c04 100644 --- a/source/credentials_provider_process.c +++ b/source/credentials_provider_process.c @@ -230,10 +230,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_process( &impl, sizeof(struct aws_credentials_provider_process_impl)); - if (!provider) { - goto on_error; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_profile.c b/source/credentials_provider_profile.c index cce4ddac..9b745beb 100644 --- a/source/credentials_provider_profile.c +++ b/source/credentials_provider_profile.c @@ -187,10 +187,6 @@ static struct aws_credentials_provider *s_create_profile_based_provider( &impl, sizeof(struct aws_credentials_provider_profile_file_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_static.c b/source/credentials_provider_static.c index 55154ee3..fcf3c423 100644 --- a/source/credentials_provider_static.c +++ b/source/credentials_provider_static.c @@ -45,9 +45,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_static( const struct aws_credentials_provider_static_options *options) { struct aws_credentials_provider *provider = aws_mem_acquire(allocator, sizeof(struct aws_credentials_provider)); - if (provider == NULL) { - return NULL; - } AWS_ZERO_STRUCT(*provider); diff --git a/source/credentials_provider_sts.c b/source/credentials_provider_sts.c index 0832cdee..731f2e5e 100644 --- a/source/credentials_provider_sts.c +++ b/source/credentials_provider_sts.c @@ -697,9 +697,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_sts( sizeof(struct aws_credentials_provider_sts_impl)); AWS_LOGF_DEBUG(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "static: creating STS credentials provider"); - if (!provider) { - return NULL; - } AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_provider_sts_web_identity.c b/source/credentials_provider_sts_web_identity.c index 8dde03e3..f08e7655 100644 --- a/source/credentials_provider_sts_web_identity.c +++ b/source/credentials_provider_sts_web_identity.c @@ -988,9 +988,7 @@ static struct sts_web_identity_parameters *s_parameters_new( struct sts_web_identity_parameters *parameters = aws_mem_calloc(allocator, 1, sizeof(struct sts_web_identity_parameters)); - if (parameters == NULL) { - return NULL; - } + parameters->allocator = allocator; bool success = false; diff --git a/source/credentials_provider_x509.c b/source/credentials_provider_x509.c index 8917636a..2ec1339b 100644 --- a/source/credentials_provider_x509.c +++ b/source/credentials_provider_x509.c @@ -541,10 +541,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_x509( &impl, sizeof(struct aws_credentials_provider_x509_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); diff --git a/source/credentials_utils.c b/source/credentials_utils.c index 47ca8863..830116a1 100644 --- a/source/credentials_utils.c +++ b/source/credentials_utils.c @@ -275,6 +275,7 @@ struct aws_credentials *aws_parse_credentials_from_json_document( struct aws_json_value *document_root = aws_json_value_new_from_string(allocator, document); if (document_root == NULL) { AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "Failed to parse document as Json document."); + aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); return NULL; } @@ -284,6 +285,7 @@ struct aws_credentials *aws_parse_credentials_from_json_document( aws_json_value_get_from_object(document_root, aws_byte_cursor_from_c_str(options->top_level_object_name)); if (!top_level_object) { AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "failed to parse top level object in json document."); + aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); goto done; } } diff --git a/source/signable.c b/source/signable.c index 9b1d526f..59b674f6 100644 --- a/source/signable.c +++ b/source/signable.c @@ -139,10 +139,6 @@ struct aws_signable *aws_signable_new_canonical_request( &impl, sizeof(struct aws_signable_canonical_request_impl)); - if (signable == NULL || impl == NULL) { - return NULL; - } - AWS_ZERO_STRUCT(*signable); AWS_ZERO_STRUCT(*impl); diff --git a/source/signable_chunk.c b/source/signable_chunk.c index 8ce78504..43c64a7c 100644 --- a/source/signable_chunk.c +++ b/source/signable_chunk.c @@ -89,10 +89,6 @@ struct aws_signable *aws_signable_new_chunk( aws_mem_acquire_many( allocator, 2, &signable, sizeof(struct aws_signable), &impl, sizeof(struct aws_signable_chunk_impl)); - if (signable == NULL || impl == NULL) { - return NULL; - } - AWS_ZERO_STRUCT(*signable); AWS_ZERO_STRUCT(*impl); diff --git a/source/signing_result.c b/source/signing_result.c index b0f8eb90..1933333e 100644 --- a/source/signing_result.c +++ b/source/signing_result.c @@ -130,9 +130,6 @@ static struct aws_array_list *s_get_or_create_property_list( } struct aws_array_list *properties = aws_mem_acquire(result->allocator, sizeof(struct aws_array_list)); - if (properties == NULL) { - return NULL; - } AWS_ZERO_STRUCT(*properties); struct aws_string *name_copy = aws_string_new_from_string(result->allocator, list_name); diff --git a/tests/credentials_provider_utils.c b/tests/credentials_provider_utils.c index 3ccd6182..9e787ed6 100644 --- a/tests/credentials_provider_utils.c +++ b/tests/credentials_provider_utils.c @@ -148,10 +148,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_mock( &impl, sizeof(struct aws_credentials_provider_mock_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); @@ -330,10 +326,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_mock_async( &impl, sizeof(struct aws_credentials_provider_mock_async_impl)); - if (!provider) { - return NULL; - } - AWS_ZERO_STRUCT(*provider); AWS_ZERO_STRUCT(*impl); @@ -458,9 +450,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_null( struct aws_credentials_provider_shutdown_options *shutdown_options) { struct aws_credentials_provider *provider = (struct aws_credentials_provider *)aws_mem_acquire(allocator, sizeof(struct aws_credentials_provider)); - if (provider == NULL) { - return NULL; - } AWS_ZERO_STRUCT(*provider);