diff --git a/bin/elasticurl/main.c b/bin/elasticurl/main.c index ba2e896f6..3e78541d0 100644 --- a/bin/elasticurl/main.c +++ b/bin/elasticurl/main.c @@ -763,7 +763,7 @@ int main(int argc, char **argv) { } if (app_ctx.input_body) { - aws_input_stream_destroy(app_ctx.input_body); + aws_input_stream_release(app_ctx.input_body); } if (app_ctx.input_file) { diff --git a/builder.json b/builder.json index c2d31e47b..66dc1e9f3 100644 --- a/builder.json +++ b/builder.json @@ -11,7 +11,8 @@ { "name": "aws-c-compression" } ], "downstream": [ - { "name": "aws-c-auth" } + { "name": "aws-c-auth" }, + { "name": "aws-c-mqtt" } ], "test_steps": [ ["bash", "./.builder/action/aws-c-http-test.sh"], diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index 4241a63f5..0ebd7b074 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -10,7 +10,7 @@ phases: pre_build: commands: - export CC=gcc-7 - - export BUILDER_VERSION=v0.8.27 + - export BUILDER_VERSION=v0.9.12 - export BUILDER_SOURCE=releases - export BUILDER_HOST=https://d19elf31gohf1l.cloudfront.net build: diff --git a/source/h1_encoder.c b/source/h1_encoder.c index e72f47ddb..1899d2f40 100644 --- a/source/h1_encoder.c +++ b/source/h1_encoder.c @@ -256,7 +256,7 @@ int aws_h1_encoder_message_init_from_request( AWS_ZERO_STRUCT(*message); - message->body = aws_http_message_get_body_stream(request); + message->body = aws_input_stream_acquire(aws_http_message_get_body_stream(request)); message->pending_chunk_list = pending_chunk_list; struct aws_byte_cursor method; @@ -352,7 +352,7 @@ int aws_h1_encoder_message_init_from_response( AWS_ZERO_STRUCT(*message); - message->body = aws_http_message_get_body_stream(response); + message->body = aws_input_stream_acquire(aws_http_message_get_body_stream(response)); message->pending_chunk_list = pending_chunk_list; struct aws_byte_cursor version = aws_http_version_to_str(AWS_HTTP_VERSION_1_1); @@ -432,6 +432,7 @@ int aws_h1_encoder_message_init_from_response( } void aws_h1_encoder_message_clean_up(struct aws_h1_encoder_message *message) { + aws_input_stream_release(message->body); aws_byte_buf_clean_up(&message->outgoing_head_buf); aws_h1_trailer_destroy(message->trailer); AWS_ZERO_STRUCT(*message); @@ -547,18 +548,18 @@ struct aws_h1_chunk *aws_h1_chunk_new(struct aws_allocator *allocator, const str } chunk->allocator = allocator; - chunk->data = options->chunk_data; + chunk->data = aws_input_stream_acquire(options->chunk_data); chunk->data_size = options->chunk_data_size; chunk->on_complete = options->on_complete; chunk->user_data = options->user_data; chunk->chunk_line = aws_byte_buf_from_empty_array(chunk_line_storage, chunk_line_size); s_populate_chunk_line_buffer(&chunk->chunk_line, options); - return chunk; } void aws_h1_chunk_destroy(struct aws_h1_chunk *chunk) { AWS_PRECONDITION(chunk); + aws_input_stream_release(chunk->data); aws_mem_release(chunk->allocator, chunk); } diff --git a/source/request_response.c b/source/request_response.c index 6d060cf09..1c42860ff 100644 --- a/source/request_response.c +++ b/source/request_response.c @@ -552,7 +552,7 @@ struct aws_http_message *aws_http_message_release(struct aws_http_message *messa } aws_http_headers_release(message->headers); - + aws_input_stream_release(message->body_stream); aws_mem_release(message->allocator, message); } else { AWS_ASSERT(prev_refcount != 0); @@ -727,7 +727,13 @@ int aws_http_message_set_response_status(struct aws_http_message *response_messa void aws_http_message_set_body_stream(struct aws_http_message *message, struct aws_input_stream *body_stream) { AWS_PRECONDITION(message); + /* release previous stream, if any */ + aws_input_stream_release(message->body_stream); + message->body_stream = body_stream; + if (message->body_stream) { + aws_input_stream_acquire(message->body_stream); + } } int aws_http1_stream_write_chunk(struct aws_http_stream *http1_stream, const struct aws_http1_chunk_options *options) { diff --git a/tests/fuzz/fuzz_h2_decoder_correct.c b/tests/fuzz/fuzz_h2_decoder_correct.c index 84ad88ddb..d6ea3201c 100644 --- a/tests/fuzz/fuzz_h2_decoder_correct.c +++ b/tests/fuzz/fuzz_h2_decoder_correct.c @@ -42,8 +42,10 @@ static struct aws_http_headers *s_generate_headers( struct aws_http_header path = {.name = aws_http_header_path, .value = aws_byte_cursor_from_c_str("/")}; aws_http_headers_add_header(headers, &path); - struct aws_http_header authority = {.name = aws_http_header_authority, - .value = aws_byte_cursor_from_c_str("example.com")}; + struct aws_http_header authority = { + .name = aws_http_header_authority, + .value = aws_byte_cursor_from_c_str("example.com"), + }; aws_http_headers_add_header(headers, &authority); } else if (header_style == HEADER_STYLE_RESPONSE) { @@ -252,7 +254,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { struct aws_stream_status body_status; aws_input_stream_get_status(body, &body_status); AWS_FATAL_ASSERT(body_complete == body_status.is_end_of_stream) - aws_input_stream_destroy(body); + aws_input_stream_release(body); break; } case AWS_H2_FRAME_T_HEADERS: { diff --git a/tests/h2_test_helper.c b/tests/h2_test_helper.c index 73d70e186..2b77f7053 100644 --- a/tests/h2_test_helper.c +++ b/tests/h2_test_helper.c @@ -611,7 +611,7 @@ int h2_fake_peer_send_data_frame_with_padding_length( ASSERT_TRUE(msg->message_data.len != 0); ASSERT_SUCCESS(testing_channel_push_read_message(peer->testing_channel, msg)); - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); return AWS_OP_SUCCESS; } @@ -643,6 +643,8 @@ int h2_fake_peer_send_connection_preface_default_settings(struct h2_fake_peer *p /******************************************************************************/ struct aws_input_stream_tester { + struct aws_input_stream base; + struct aws_allocator *allocator; /* aws_input_stream_byte_cursor provides our actual functionality */ struct aws_input_stream *cursor_stream; @@ -655,12 +657,12 @@ static int s_aws_input_stream_tester_seek( int64_t offset, enum aws_stream_seek_basis basis) { - struct aws_input_stream_tester *impl = stream->impl; + struct aws_input_stream_tester *impl = AWS_CONTAINER_OF(stream, struct aws_input_stream_tester, base); return aws_input_stream_seek(impl->cursor_stream, offset, basis); } static int s_aws_input_stream_tester_read(struct aws_input_stream *stream, struct aws_byte_buf *dest) { - struct aws_input_stream_tester *impl = stream->impl; + struct aws_input_stream_tester *impl = AWS_CONTAINER_OF(stream, struct aws_input_stream_tester, base); if (impl->is_reading_broken) { return aws_raise_error(AWS_IO_STREAM_READ_FAILED); @@ -678,21 +680,18 @@ static int s_aws_input_stream_tester_read(struct aws_input_stream *stream, struc } static int s_aws_input_stream_tester_get_status(struct aws_input_stream *stream, struct aws_stream_status *status) { - struct aws_input_stream_tester *impl = stream->impl; + struct aws_input_stream_tester *impl = AWS_CONTAINER_OF(stream, struct aws_input_stream_tester, base); return aws_input_stream_get_status(impl->cursor_stream, status); } static int s_aws_input_stream_tester_get_length(struct aws_input_stream *stream, int64_t *out_length) { - struct aws_input_stream_tester *impl = stream->impl; + struct aws_input_stream_tester *impl = AWS_CONTAINER_OF(stream, struct aws_input_stream_tester, base); return aws_input_stream_get_length(impl->cursor_stream, out_length); } -static void s_aws_input_stream_tester_destroy(struct aws_input_stream *stream) { - if (stream) { - struct aws_input_stream_tester *impl = stream->impl; - aws_input_stream_destroy(impl->cursor_stream); - aws_mem_release(stream->allocator, stream); - } +static void s_aws_input_stream_tester_destroy(struct aws_input_stream_tester *impl) { + aws_input_stream_release(impl->cursor_stream); + aws_mem_release(impl->allocator, impl); } static struct aws_input_stream_vtable s_aws_input_stream_tester_vtable = { @@ -700,38 +699,30 @@ static struct aws_input_stream_vtable s_aws_input_stream_tester_vtable = { .read = s_aws_input_stream_tester_read, .get_status = s_aws_input_stream_tester_get_status, .get_length = s_aws_input_stream_tester_get_length, - .destroy = s_aws_input_stream_tester_destroy, }; struct aws_input_stream *aws_input_stream_new_tester(struct aws_allocator *alloc, struct aws_byte_cursor cursor) { - struct aws_input_stream *stream = NULL; - struct aws_input_stream_tester *impl = NULL; - aws_mem_acquire_many( - alloc, 2, &stream, sizeof(struct aws_input_stream), &impl, sizeof(struct aws_input_stream_tester)); - AWS_FATAL_ASSERT(stream); - - AWS_ZERO_STRUCT(*stream); - AWS_ZERO_STRUCT(*impl); - - stream->allocator = alloc; - stream->impl = impl; - stream->vtable = &s_aws_input_stream_tester_vtable; + struct aws_input_stream_tester *impl = aws_mem_calloc(alloc, 1, sizeof(struct aws_input_stream_tester)); + AWS_FATAL_ASSERT(impl); impl->max_bytes_per_read = SIZE_MAX; impl->cursor_stream = aws_input_stream_new_from_cursor(alloc, &cursor); AWS_FATAL_ASSERT(impl->cursor_stream); - - return stream; + impl->allocator = alloc; + impl->base.vtable = &s_aws_input_stream_tester_vtable; + aws_ref_count_init( + &impl->base.ref_count, impl, (aws_simple_completion_callback *)s_aws_input_stream_tester_destroy); + return &impl->base; } void aws_input_stream_tester_set_max_bytes_per_read(struct aws_input_stream *input_stream, size_t max_bytes) { - struct aws_input_stream_tester *impl = input_stream->impl; + struct aws_input_stream_tester *impl = AWS_CONTAINER_OF(input_stream, struct aws_input_stream_tester, base); impl->max_bytes_per_read = max_bytes; } void aws_input_stream_tester_set_reading_broken(struct aws_input_stream *input_stream, bool is_broken) { - struct aws_input_stream_tester *impl = input_stream->impl; + struct aws_input_stream_tester *impl = AWS_CONTAINER_OF(input_stream, struct aws_input_stream_tester, base); impl->is_reading_broken = is_broken; } diff --git a/tests/test_connection_monitor.c b/tests/test_connection_monitor.c index ee637b322..c16bfd932 100644 --- a/tests/test_connection_monitor.c +++ b/tests/test_connection_monitor.c @@ -147,7 +147,7 @@ static void s_clean_up_monitor_test(void) { if (request_info) { aws_http_message_destroy(request_info->request); aws_http_stream_release(request_info->stream); - aws_input_stream_destroy(request_info->body); + aws_input_stream_release(request_info->body); } } diff --git a/tests/test_h1_client.c b/tests/test_h1_client.c index 1f90ebeda..76af7a205 100644 --- a/tests/test_h1_client.c +++ b/tests/test_h1_client.c @@ -33,7 +33,7 @@ static void s_destroy_stream_on_complete(struct aws_http_stream *stream, int err (void)stream; (void)error_code; struct aws_input_stream *data_stream = user_data; - aws_input_stream_destroy(data_stream); + aws_input_stream_release(data_stream); } static struct aws_http1_chunk_options s_default_chunk_options(struct aws_input_stream *stream, size_t stream_size) { @@ -274,7 +274,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_body) { ASSERT_SUCCESS(testing_channel_check_written_messages_str(&tester.testing_channel, allocator, expected)); /* clean up */ - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_http_stream_release(stream); @@ -892,7 +892,7 @@ static void s_on_chunk_complete_write_another_chunk(struct aws_http_stream *stre AWS_FATAL_ASSERT(0 == error_code); struct chunk_that_writes_another *chunk = user_data; - aws_input_stream_destroy(chunk->body_data); + aws_input_stream_release(chunk->body_data); const struct aws_byte_cursor chunk2_body = aws_byte_cursor_from_c_str("chunk 2."); struct aws_input_stream *chunk2_body_stream = aws_input_stream_new_from_cursor(chunk->allocator, &chunk2_body); @@ -1083,7 +1083,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_content_length_0_ok) { ASSERT_SUCCESS(testing_channel_check_written_message_str(&tester.testing_channel, expected)); /* clean up */ - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_http_stream_release(stream); @@ -1236,7 +1236,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_large_body) { &tester.testing_channel, allocator, aws_byte_cursor_from_buf(&expected_buf))); /* clean up */ - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_http_stream_release(stream); @@ -2135,6 +2135,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_with_too_much_data_shuts_down_connection) } struct slow_body_sender { + struct aws_input_stream base; struct aws_stream_status status; struct aws_byte_cursor cursor; size_t delay_ticks; /* Don't send anything the first N ticks */ @@ -2142,7 +2143,7 @@ struct slow_body_sender { }; static int s_slow_stream_read(struct aws_input_stream *stream, struct aws_byte_buf *dest) { - struct slow_body_sender *sender = stream->impl; + struct slow_body_sender *sender = AWS_CONTAINER_OF(stream, struct slow_body_sender, base); size_t dst_available = dest->capacity - dest->len; size_t writing = 0; @@ -2170,17 +2171,17 @@ static int s_slow_stream_read(struct aws_input_stream *stream, struct aws_byte_b return AWS_OP_SUCCESS; } static int s_slow_stream_get_status(struct aws_input_stream *stream, struct aws_stream_status *status) { - struct slow_body_sender *sender = stream->impl; + struct slow_body_sender *sender = AWS_CONTAINER_OF(stream, struct slow_body_sender, base); *status = sender->status; return AWS_OP_SUCCESS; } static int s_slow_stream_get_length(struct aws_input_stream *stream, int64_t *out_length) { - struct slow_body_sender *sender = stream->impl; + struct slow_body_sender *sender = AWS_CONTAINER_OF(stream, struct slow_body_sender, base); *out_length = sender->cursor.len; return AWS_OP_SUCCESS; } static void s_slow_stream_destroy(struct aws_input_stream *stream) { - aws_mem_release(stream->allocator, stream); + (void)stream; } static struct aws_input_stream_vtable s_slow_stream_vtable = { @@ -2188,7 +2189,6 @@ static struct aws_input_stream_vtable s_slow_stream_vtable = { .read = s_slow_stream_read, .get_status = s_slow_stream_get_status, .get_length = s_slow_stream_get_length, - .destroy = s_slow_stream_destroy, }; /* It should be fine to receive a response before the request has finished sending */ @@ -2198,7 +2198,10 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok ASSERT_SUCCESS(s_tester_init(&tester, allocator)); /* set up request whose body won't send immediately */ + struct aws_input_stream empty_stream_base; + AWS_ZERO_STRUCT(empty_stream_base); struct slow_body_sender body_sender = { + .base = empty_stream_base, .status = { .is_end_of_stream = false, @@ -2208,11 +2211,11 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok .delay_ticks = 5, .bytes_per_tick = 1, }; - struct aws_input_stream body_stream = { - .allocator = allocator, - .impl = &body_sender, - .vtable = &s_slow_stream_vtable, - }; + body_sender.base.vtable = &s_slow_stream_vtable; + aws_ref_count_init( + &body_sender.base.ref_count, &body_sender, (aws_simple_completion_callback *)s_slow_stream_destroy); + + struct aws_input_stream *body_stream = &body_sender.base; struct aws_http_header headers[] = { { @@ -2226,7 +2229,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok ASSERT_SUCCESS(aws_http_message_set_request_method(request, aws_byte_cursor_from_c_str("PUT"))); ASSERT_SUCCESS(aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/plan.txt"))); ASSERT_SUCCESS(aws_http_message_add_header_array(request, headers, AWS_ARRAY_SIZE(headers))); - aws_http_message_set_body_stream(request, &body_stream); + aws_http_message_set_body_stream(request, body_stream); struct client_stream_tester stream_tester; ASSERT_SUCCESS(s_stream_tester_init(&stream_tester, &tester, request)); @@ -2236,6 +2239,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok /* Ensure the request can be destroyed after request is sent */ aws_http_message_destroy(request); + aws_input_stream_release(body_stream); /* send response */ ASSERT_SUCCESS(testing_channel_push_read_str(&tester.testing_channel, "HTTP/1.1 200 OK\r\n\r\n")); @@ -2277,7 +2281,10 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_chunks_done_sendin ASSERT_SUCCESS(s_tester_init(&tester, allocator)); /* set up request whose body won't send immediately */ + struct aws_input_stream empty_stream_base; + AWS_ZERO_STRUCT(empty_stream_base); struct slow_body_sender body_sender = { + .base = empty_stream_base, .status = { .is_end_of_stream = false, @@ -2287,11 +2294,11 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_chunks_done_sendin .delay_ticks = 5, .bytes_per_tick = 1, }; - struct aws_input_stream body_stream = { - .allocator = allocator, - .impl = &body_sender, - .vtable = &s_slow_stream_vtable, - }; + body_sender.base.vtable = &s_slow_stream_vtable; + aws_ref_count_init( + &body_sender.base.ref_count, &body_sender, (aws_simple_completion_callback *)s_slow_stream_destroy); + + struct aws_input_stream *body_stream = &body_sender.base; struct aws_http_message *request = s_new_default_chunked_put_request(allocator); struct client_stream_tester stream_tester; @@ -2305,13 +2312,14 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_chunks_done_sendin testing_channel_run_currently_queued_tasks(&tester.testing_channel); - struct aws_http1_chunk_options options = s_default_chunk_options(&body_stream, body_sender.cursor.len); + struct aws_http1_chunk_options options = s_default_chunk_options(body_stream, body_sender.cursor.len); options.on_complete = NULL; /* The stream_tester takes care of the stream deletion */ ASSERT_SUCCESS(aws_http1_stream_write_chunk(stream_tester.stream, &options)); ASSERT_SUCCESS(s_write_termination_chunk(allocator, stream_tester.stream)); /* Ensure the request can be destroyed after request is sent */ aws_http_message_destroy(request); + aws_input_stream_release(body_stream); /* tick loop until body finishes sending.*/ while (body_sender.cursor.len > 0) { @@ -3060,7 +3068,7 @@ static int s_test_content_length_mismatch_is_error( ASSERT_INT_EQUALS(AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT, completion_error_code); /* clean up */ - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_http_stream_release(stream); @@ -3302,11 +3310,13 @@ enum request_callback { static const int ERROR_FROM_CALLBACK_ERROR_CODE = (int)0xBEEFCAFE; struct error_from_callback_tester { + struct aws_input_stream base; enum request_callback error_at; int callback_counts[REQUEST_CALLBACK_COUNT]; bool has_errored; struct aws_stream_status status; int on_complete_error_code; + struct aws_allocator *alloc; }; static int s_error_from_callback_common( @@ -3330,7 +3340,7 @@ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct (void)dest; - struct error_from_callback_tester *error_tester = body->impl; + struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) { return AWS_OP_ERR; } @@ -3342,13 +3352,13 @@ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct } static int s_error_from_outgoing_body_get_status(struct aws_input_stream *body, struct aws_stream_status *status) { - struct error_from_callback_tester *error_tester = body->impl; + struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); *status = error_tester->status; return AWS_OP_SUCCESS; } static void s_error_from_outgoing_body_destroy(struct aws_input_stream *stream) { - aws_mem_release(stream->allocator, stream); + (void)stream; } static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { @@ -3356,7 +3366,6 @@ static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { .read = s_error_from_outgoing_body_read, .get_status = s_error_from_outgoing_body_get_status, .get_length = NULL, - .destroy = s_error_from_outgoing_body_destroy, }; static int s_error_from_incoming_headers( @@ -3403,7 +3412,10 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, enum requ struct tester tester; ASSERT_SUCCESS(s_tester_init(&tester, allocator)); + struct aws_input_stream empty_stream_base; + AWS_ZERO_STRUCT(empty_stream_base); struct error_from_callback_tester error_tester = { + .base = empty_stream_base, .error_at = error_at, .status = { @@ -3411,12 +3423,12 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, enum requ .is_end_of_stream = false, }, }; - struct aws_input_stream error_from_outgoing_body_stream = { - .allocator = allocator, - .impl = &error_tester, - .vtable = &s_error_from_outgoing_body_vtable, - }; - + error_tester.base.vtable = &s_error_from_outgoing_body_vtable; + aws_ref_count_init( + &error_tester.base.ref_count, + &error_tester, + (aws_simple_completion_callback *)s_error_from_outgoing_body_destroy); + struct aws_input_stream *error_from_outgoing_body_stream = &error_tester.base; /* send request */ struct aws_http_header headers[] = { { @@ -3430,7 +3442,7 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, enum requ ASSERT_SUCCESS(aws_http_message_set_request_method(request, aws_http_method_post)); ASSERT_SUCCESS(aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/"))); ASSERT_SUCCESS(aws_http_message_add_header_array(request, headers, AWS_ARRAY_SIZE(headers))); - aws_http_message_set_body_stream(request, &error_from_outgoing_body_stream); + aws_http_message_set_body_stream(request, error_from_outgoing_body_stream); struct aws_http_make_request_options opt = { .self_size = sizeof(opt), @@ -3450,6 +3462,7 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, enum requ /* Ensure the request can be destroyed after request is sent */ aws_http_message_destroy(opt.request); + aws_input_stream_release(error_from_outgoing_body_stream); /* send response */ ASSERT_SUCCESS(testing_channel_push_read_str_ignore_errors( diff --git a/tests/test_h1_encoder.c b/tests/test_h1_encoder.c index 0deada1bc..378472b43 100644 --- a/tests/test_h1_encoder.c +++ b/tests/test_h1_encoder.c @@ -76,7 +76,7 @@ H1_ENCODER_TEST_CASE(h1_encoder_content_length_put_request_headers) { ASSERT_FALSE(encoder_message.has_connection_close_header); ASSERT_UINT_EQUALS(body.len, encoder_message.content_length); - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_h1_encoder_message_clean_up(&encoder_message); aws_h1_encoder_clean_up(&encoder); @@ -232,7 +232,7 @@ H1_ENCODER_TEST_CASE(h1_encoder_transfer_encoding_not_chunked_put_request_header ASSERT_FALSE(encoder_message.has_connection_close_header); ASSERT_UINT_EQUALS(0, encoder_message.content_length); - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_h1_encoder_message_clean_up(&encoder_message); aws_h1_encoder_clean_up(&encoder); @@ -274,7 +274,7 @@ H1_ENCODER_TEST_CASE(h1_encoder_transfer_encoding_set_body_stream_errors) { ASSERT_FALSE(encoder_message.has_connection_close_header); ASSERT_UINT_EQUALS(0, encoder_message.content_length); - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_h1_encoder_message_clean_up(&encoder_message); aws_h1_encoder_clean_up(&encoder); @@ -396,7 +396,7 @@ H1_ENCODER_TEST_CASE(h1_encoder_transfer_encoding_chunked_and_content_length_put ASSERT_INT_EQUALS( AWS_OP_ERR, aws_h1_encoder_message_init_from_request(&encoder_message, allocator, request, &chunk_list)); - aws_input_stream_destroy(body_stream); + aws_input_stream_release(body_stream); aws_http_message_destroy(request); aws_h1_encoder_message_clean_up(&encoder_message); aws_h1_encoder_clean_up(&encoder); diff --git a/tests/test_h1_server.c b/tests/test_h1_server.c index 7d3786108..2a6921280 100644 --- a/tests/test_h1_server.c +++ b/tests/test_h1_server.c @@ -209,7 +209,7 @@ static int s_server_request_clean_up(void) { for (int i = 0; i < s_tester.request_num; i++) { aws_http_stream_release(s_tester.requests[i].request_handler); aws_byte_buf_clean_up(&s_tester.requests[i].storage); - aws_input_stream_destroy(s_tester.requests[i].response_body); + aws_input_stream_release(s_tester.requests[i].response_body); } return AWS_OP_SUCCESS; } @@ -1303,6 +1303,7 @@ enum request_handler_callback { static const int ERROR_FROM_CALLBACK_ERROR_CODE = (int)0xBEEFCAFE; struct error_from_callback_tester { + struct aws_input_stream base; enum request_handler_callback error_at; int callback_counts[REQUEST_HANDLER_CALLBACK_COUNT]; bool has_errored; @@ -1341,7 +1342,7 @@ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct (void)dest; - struct error_from_callback_tester *error_tester = body->impl; + struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); ASSERT_SUCCESS(s_error_from_callback_common(error_tester, REQUEST_HANDLER_CALLBACK_OUTGOING_BODY)); /* If the common fn was successful, write out some data and end the stream */ @@ -1351,13 +1352,13 @@ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct } static int s_error_from_outgoing_body_get_status(struct aws_input_stream *body, struct aws_stream_status *status) { - struct error_from_callback_tester *error_tester = body->impl; + struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); *status = error_tester->outgoing_body_status; return AWS_OP_SUCCESS; } -static void s_error_from_outgoing_body_destroy(struct aws_input_stream *stream) { - aws_mem_release(stream->allocator, stream); +static void s_error_from_outgoing_body_destroy(struct aws_input_stream *body) { + (void)body; } static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { @@ -1365,7 +1366,6 @@ static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { .read = s_error_from_outgoing_body_read, .get_status = s_error_from_outgoing_body_get_status, .get_length = NULL, - .destroy = s_error_from_outgoing_body_destroy, }; static int s_error_from_incoming_headers( @@ -1553,15 +1553,17 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, enum requ }, }; - struct aws_input_stream error_from_outgoing_body_stream = { - .allocator = allocator, - .impl = &error_tester, - .vtable = &s_error_from_outgoing_body_vtable, - }; + error_tester.base.vtable = &s_error_from_outgoing_body_vtable; + aws_ref_count_init( + &error_tester.base.ref_count, + &error_tester, + (aws_simple_completion_callback *)s_error_from_outgoing_body_destroy); + + struct aws_input_stream *error_from_outgoing_body_stream = &error_tester.base; struct aws_http_message *response; ASSERT_SUCCESS( - s_create_response(&response, 200, headers, AWS_ARRAY_SIZE(headers), &error_from_outgoing_body_stream)); + s_create_response(&response, 200, headers, AWS_ARRAY_SIZE(headers), error_from_outgoing_body_stream)); /* send_response() may succeed or fail, depending on when things shut down */ aws_http_stream_send_response(request->request_handler, response); @@ -1581,6 +1583,7 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, enum requ ASSERT_INT_EQUALS(ERROR_FROM_CALLBACK_ERROR_CODE, error_tester.on_complete_error_code); aws_http_message_destroy(response); + aws_input_stream_release(error_from_outgoing_body_stream); ASSERT_SUCCESS(s_server_error_tester_clean_up(&error_tester)); return AWS_OP_SUCCESS; } diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index ef42461b8..b72a64a8c 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -318,7 +318,7 @@ TEST_CASE(h2_client_auto_ping_ack_higher_priority) { /* clean up */ aws_http_message_release(request); client_stream_tester_clean_up(&stream_tester); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -790,7 +790,7 @@ TEST_CASE(h2_client_stream_err_state_forbids_frame) { aws_http_headers_release(response_headers); aws_http_message_release(request); client_stream_tester_clean_up(&stream_tester); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -1524,7 +1524,7 @@ TEST_CASE(h2_client_stream_send_data) { aws_http_headers_release(response_headers); aws_http_message_release(request); client_stream_tester_clean_up(&stream_tester); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -1672,7 +1672,7 @@ TEST_CASE(h2_client_stream_send_lots_of_data) { for (size_t i = 0; i < NUM_STREAMS; ++i) { client_stream_tester_clean_up(&stream_testers[i]); aws_http_message_release(requests[i]); - aws_input_stream_destroy(request_bodies[i]); + aws_input_stream_release(request_bodies[i]); aws_byte_buf_clean_up(&request_body_bufs[i]); } return s_tester_clean_up(); @@ -1746,7 +1746,7 @@ TEST_CASE(h2_client_stream_send_stalled_data) { /* clean up */ aws_http_message_release(request); client_stream_tester_clean_up(&stream_tester); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -1858,7 +1858,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_stream_window_size) { aws_http_headers_release(response_headers); aws_http_message_release(request); client_stream_tester_clean_up(&stream_tester); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -1968,7 +1968,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_negative_stream_window_size) aws_http_headers_release(response_headers); aws_http_message_release(request); client_stream_tester_clean_up(&stream_tester); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -2092,7 +2092,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_connection_window_size) { for (size_t i = 0; i < NUM_STREAMS; ++i) { client_stream_tester_clean_up(&stream_testers[i]); aws_http_message_release(requests[i]); - aws_input_stream_destroy(request_bodies[i]); + aws_input_stream_release(request_bodies[i]); aws_byte_buf_clean_up(&request_body_bufs[i]); } return s_tester_clean_up(); @@ -2295,7 +2295,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_connection_and_stream_window_ for (size_t i = 0; i < NUM_STREAMS; ++i) { client_stream_tester_clean_up(&stream_testers[i]); aws_http_message_release(requests[i]); - aws_input_stream_destroy(request_bodies[i]); + aws_input_stream_release(request_bodies[i]); aws_byte_buf_clean_up(&request_body_bufs[i]); } return s_tester_clean_up(); @@ -2832,7 +2832,7 @@ TEST_CASE(h2_client_stream_receive_end_stream_before_done_sending) { aws_http_headers_release(response_headers); client_stream_tester_clean_up(&stream_tester); aws_http_message_release(request); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -2904,7 +2904,7 @@ TEST_CASE(h2_client_stream_receive_end_stream_and_rst_before_done_sending) { aws_http_headers_release(response_headers); client_stream_tester_clean_up(&stream_tester); aws_http_message_release(request); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } @@ -2949,7 +2949,7 @@ TEST_CASE(h2_client_stream_err_input_stream_failure) { /* clean up */ client_stream_tester_clean_up(&stream_tester); aws_http_message_release(request); - aws_input_stream_destroy(request_body); + aws_input_stream_release(request_body); return s_tester_clean_up(); } diff --git a/tests/test_h2_encoder.c b/tests/test_h2_encoder.c index 9aab69bfb..ad0bb34f4 100644 --- a/tests/test_h2_encoder.c +++ b/tests/test_h2_encoder.c @@ -104,7 +104,7 @@ TEST_CASE(h2_encoder_data) { ASSERT_FALSE(body_stalled); aws_byte_buf_clean_up(&output); - aws_input_stream_destroy(body); + aws_input_stream_release(body); aws_h2_frame_encoder_clean_up(&encoder); return AWS_OP_SUCCESS; } @@ -158,7 +158,7 @@ TEST_CASE(h2_encoder_data_stalled) { ASSERT_TRUE(body_stalled); aws_byte_buf_clean_up(&output); - aws_input_stream_destroy(body); + aws_input_stream_release(body); aws_h2_frame_encoder_clean_up(&encoder); return AWS_OP_SUCCESS; } @@ -201,7 +201,7 @@ TEST_CASE(h2_encoder_data_stalled_completely) { /* clean up */ aws_byte_buf_clean_up(&output); - aws_input_stream_destroy(body); + aws_input_stream_release(body); aws_h2_frame_encoder_clean_up(&encoder); return AWS_OP_SUCCESS; }