@@ -1036,6 +1036,7 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
10361036 const size_t prev_len = dst -> len ;
10371037 int err = aws_input_stream_read (data_write -> data , dst );
10381038 const size_t amount_read = dst -> len - prev_len ;
1039+ int error_code = AWS_OP_ERR ;
10391040
10401041 if (err ) {
10411042 ENCODER_LOGF (
@@ -1044,10 +1045,10 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
10441045 "Failed to read data write stream, error %d (%s)" ,
10451046 aws_last_error (),
10461047 aws_error_name (aws_last_error ()));
1047- int error_code = aws_last_error ();
1048+ error_code = aws_last_error ();
10481049 aws_h1_data_write_complete_and_destroy (data_write , encoder -> current_stream , error_code );
10491050 encoder -> message -> current_data_write = NULL ;
1050- return aws_raise_error ( error_code ) ;
1051+ goto error ;
10511052 }
10521053
10531054 /* Increment progress_bytes and check we haven't exceeded Content-Length */
@@ -1058,7 +1059,8 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
10581059 aws_h1_data_write_complete_and_destroy (
10591060 data_write , encoder -> current_stream , AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT );
10601061 encoder -> message -> current_data_write = NULL ;
1061- return aws_raise_error (AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT );
1062+ error_code = AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT ;
1063+ goto error ;
10621064 }
10631065
10641066 ENCODER_LOGF (
@@ -1080,10 +1082,10 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
10801082 "Failed to query data write stream status, error %d (%s)" ,
10811083 aws_last_error (),
10821084 aws_error_name (aws_last_error ()));
1083- int error_code = aws_last_error ();
1085+ error_code = aws_last_error ();
10841086 aws_h1_data_write_complete_and_destroy (data_write , encoder -> current_stream , error_code );
10851087 encoder -> message -> current_data_write = NULL ;
1086- return aws_raise_error ( error_code ) ;
1088+ goto error ;
10871089 }
10881090
10891091 if (!status .is_end_of_stream ) {
@@ -1102,10 +1104,10 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
11021104 "Failed to query data write stream status, error %d (%s)" ,
11031105 aws_last_error (),
11041106 aws_error_name (aws_last_error ()));
1105- int error_code = aws_last_error ();
1107+ error_code = aws_last_error ();
11061108 aws_h1_data_write_complete_and_destroy (data_write , encoder -> current_stream , error_code );
11071109 encoder -> message -> current_data_write = NULL ;
1108- return aws_raise_error ( error_code ) ;
1110+ goto error ;
11091111 }
11101112
11111113 if (!status .is_end_of_stream ) {
@@ -1128,13 +1130,17 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
11281130 "Manual data writes sent %" PRIu64 " bytes but Content-Length is %" PRIu64 ,
11291131 encoder -> progress_bytes ,
11301132 encoder -> message -> content_length );
1131- return aws_raise_error (AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT );
1133+ error_code = AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT ;
1134+ goto error ;
11321135 }
11331136 return s_switch_state (encoder , AWS_H1_ENCODER_STATE_DONE );
11341137 }
11351138
11361139 /* More writes expected, go back to waiting for next write */
11371140 return s_switch_state (encoder , AWS_H1_ENCODER_STATE_DATA_WRITE_NEXT );
1141+
1142+ error :
1143+ return aws_raise_error (error_code );
11381144}
11391145
11401146/* Message is done, loop back to start of state machine */
0 commit comments