@@ -87,7 +87,8 @@ struct aws_websocket_client_bootstrap {
8787static void s_ws_bootstrap_destroy (struct aws_websocket_client_bootstrap * ws_bootstrap );
8888static int s_ws_bootstrap_calculate_sec_websocket_accept (
8989 struct aws_byte_cursor sec_websocket_key ,
90- struct aws_byte_buf * out_buf );
90+ struct aws_byte_buf * out_buf ,
91+ struct aws_allocator * alloc );
9192static void s_ws_bootstrap_cancel_setup_due_to_err (
9293 struct aws_websocket_client_bootstrap * ws_bootstrap ,
9394 struct aws_http_connection * http_connection ,
@@ -166,13 +167,12 @@ int aws_websocket_client_connect(const struct aws_websocket_client_connection_op
166167 ws_bootstrap -> websocket_frame_payload_callback = options -> on_incoming_frame_payload ;
167168 ws_bootstrap -> websocket_frame_complete_callback = options -> on_incoming_frame_complete ;
168169 ws_bootstrap -> handshake_request = aws_http_message_acquire (options -> handshake_request );
169- aws_byte_buf_init (& ws_bootstrap -> expected_sec_websocket_accept , ws_bootstrap -> alloc , 0 );
170170 ws_bootstrap -> response_status = AWS_HTTP_STATUS_CODE_UNKNOWN ;
171171 ws_bootstrap -> response_headers = aws_http_headers_new (ws_bootstrap -> alloc );
172172 aws_byte_buf_init (& ws_bootstrap -> response_body , ws_bootstrap -> alloc , 0 );
173173
174174 if (s_ws_bootstrap_calculate_sec_websocket_accept (
175- sec_websocket_key , & ws_bootstrap -> expected_sec_websocket_accept )) {
175+ sec_websocket_key , & ws_bootstrap -> expected_sec_websocket_accept , ws_bootstrap -> alloc )) {
176176 goto error ;
177177 }
178178
@@ -257,18 +257,18 @@ static void s_ws_bootstrap_destroy(struct aws_websocket_client_bootstrap *ws_boo
257257 */
258258static int s_ws_bootstrap_calculate_sec_websocket_accept (
259259 struct aws_byte_cursor sec_websocket_key ,
260- struct aws_byte_buf * out_buf ) {
260+ struct aws_byte_buf * out_buf ,
261+ struct aws_allocator * alloc ) {
261262
262- AWS_ASSERT (out_buf && out_buf -> allocator && out_buf -> len == 0 ); /* expect buf to be initialized empty */
263- struct aws_allocator * alloc = out_buf -> allocator ;
263+ AWS_ASSERT (out_buf && !out_buf -> allocator && out_buf -> len == 0 ); /* expect buf to be uninitialized */
264264
265265 /* ignore leading and trailing whitespace */
266266 sec_websocket_key = aws_strutil_trim_http_whitespace (sec_websocket_key );
267267
268268 /* concatenation of key with magic string (store temporarily in out_buf) */
269269 struct aws_byte_cursor magic_string = aws_byte_cursor_from_c_str ("258EAFA5-E914-47DA-95CA-C5AB0DC85B11" );
270270
271- aws_byte_buf_reserve (out_buf , sec_websocket_key .len + magic_string .len );
271+ aws_byte_buf_init (out_buf , alloc , sec_websocket_key .len + magic_string .len );
272272 aws_byte_buf_append_dynamic (out_buf , & sec_websocket_key );
273273 aws_byte_buf_append_dynamic (out_buf , & magic_string );
274274 struct aws_byte_cursor key_and_magic_string = aws_byte_cursor_from_buf (out_buf );
0 commit comments