diff --git a/plugin/protocol/http/test/test_http_convert.cpp b/plugin/protocol/http/test/test_http_convert.cpp index a1a3ff2..3f333b7 100644 --- a/plugin/protocol/http/test/test_http_convert.cpp +++ b/plugin/protocol/http/test/test_http_convert.cpp @@ -226,8 +226,9 @@ protected: void TearDown() override { - hf_content_compress_destroy(cv_compress_object); - evbuffer_free(buf); + hf_content_uncompress_destroy(cv_uncompress_object); + hf_content_compress_destroy(cv_compress_object); + evbuffer_free(buf); } protected: diff --git a/plugin/protocol/http/test/test_http_half.cpp b/plugin/protocol/http/test/test_http_half.cpp index 1626100..00d0bab 100644 --- a/plugin/protocol/http/test/test_http_half.cpp +++ b/plugin/protocol/http/test/test_http_half.cpp @@ -29,6 +29,7 @@ TEST(HttpHalfRequestParser, ProtoIdentifyIsHTTP) strlen(__identify_http_request)); EXPECT_EQ(ret, 0); + hf_private_destory(hf_request); } TEST(HttpHalfRequestParser, ProtoIdentifyNotHTTP) @@ -40,6 +41,7 @@ TEST(HttpHalfRequestParser, ProtoIdentifyNotHTTP) strlen(__identify_not_http_request)); EXPECT_EQ(ret, -1); + hf_private_destory(hf_request); } static const char * __get_http_request_no_body = @@ -145,6 +147,7 @@ TEST(HttpHalfRequestParser, GetWithNoBody) ASSERT_EQ(ret, 1); __get_http_request_header_verify_helper(hf_request); + hf_private_destory(hf_request); } TEST(HttpHalfRequestParserCallback, GetWithNoBody) @@ -159,6 +162,7 @@ TEST(HttpHalfRequestParserCallback, GetWithNoBody) hf_private_set_callback(hf_request, __get_http_request_01_callback, &__expect_id, NULL); hf_private_parse(hf_request, __data, __datalen); __get_http_request_header_verify_helper(hf_request); + hf_private_destory(hf_request); } /* @@ -428,6 +432,7 @@ TEST(HttpHalfRequestParser, PostWithBody) ASSERT_EQ(ret, 1); __http_post_header_verify_helper(hf_request); + hf_private_destory(hf_request); } TEST(HttpHalfRequestParserCallback, PostWithBody) @@ -449,6 +454,8 @@ TEST(HttpHalfRequestParserCallback, PostWithBody) EXPECT_TRUE(ctx->req_body_cont_called); EXPECT_TRUE(ctx->req_body_end_called); EXPECT_TRUE(ctx->req_end_called); + delete(ctx); + hf_private_destory(hf_request); } class HttpHalfResponseParser : public ::testing::Test @@ -1535,6 +1542,7 @@ TEST(HttpHalfRequestParser, SplitRequestAtHeader) EXPECT_EQ(ret, 1); EXPECT_EQ(hf_request->parse_cursor, strlen(__str_test_split_http_2)); + hf_private_destory(hf_request); } TEST(HttpHalfRequestParser, SplitResponseAtHeader) @@ -1548,6 +1556,7 @@ TEST(HttpHalfRequestParser, SplitResponseAtHeader) EXPECT_EQ(ret, 0); EXPECT_EQ(hf_request->parse_cursor, strlen(__str_test_split_http_resp_1)); + hf_private_destory(hf_request); } void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...) diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 58c1f6b..96a97b3 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -315,7 +315,8 @@ int h2_half_ops_field_write(struct tfe_http_half * half, const struct http_field continue; TAILQ_REMOVE(&h2_header->h2_field_list, h2_field, next); - free(h2_field->nv.name); + free(h2_field->field); + free(h2_field->nv.name); free(h2_field->nv.value); free(h2_field); h2_header->nvlen--; diff --git a/plugin/protocol/http2/test/test_http2_stream.cpp b/plugin/protocol/http2/test/test_http2_stream.cpp index 681ebb9..029986d 100644 --- a/plugin/protocol/http2/test/test_http2_stream.cpp +++ b/plugin/protocol/http2/test/test_http2_stream.cpp @@ -118,11 +118,12 @@ void UT_Parse_ReqHeaders(nghttp2_session *as_server) xret = tfe_http_field_write(tfe_half, &field_name, "201x101x"); EXPECT_EQ(xret, 0); - field_name.field_id = TFE_HTTP_DATE; + field_name.field_id = TFE_HTTP_DATE; hdr_value = tfe_http_field_read((const struct tfe_http_half*)tfe_half, &field_name); EXPECT_STREQ(hdr_value, "201x101x"); + xret = tfe_http_field_write(tfe_half, &field_name, NULL); // delete field_name - return; + return; } void UT_Parse_RespHeaders(nghttp2_session *as_client) @@ -197,6 +198,10 @@ TEST(Http2StreamParser, GetFrameWithMagic) /*Recv data magic**/ readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, magic_headers, sizeof(magic_headers)); EXPECT_GT(readlen, 0); + + sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); + free(tapinfo->h2_stream_info); + free(tapinfo); } TEST(Http2StreamParser, GetFrameWithHeader_01) @@ -219,6 +224,10 @@ TEST(Http2StreamParser, GetFrameWithHeader_01) EXPECT_GT(readlen, 0); UT_Parse_ReqHeaders(h2_stream_info->as_server); + + sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); + free(tapinfo->h2_stream_info); + free(tapinfo); } TEST(Http2StreamParser, GetFrameWithHeader_02) @@ -244,6 +253,10 @@ TEST(Http2StreamParser, GetFrameWithHeader_02) //enum tfe_stream_action stream_action = ACTION_FORWARD_DATA; //stream_action = nghttp2_client_mem_send(h2_stream_info); //EXPECT_EQ(stream_action, ACTION_DROP_DATA); + + sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); + free(tapinfo->h2_stream_info); + free(tapinfo); } TEST(Http2StreamParser, RespFrameWithHead_01) @@ -278,6 +291,10 @@ TEST(Http2StreamParser, RespFrameWithHead_01) readlen = nghttp2_session_mem_recv(h2_stream_info->as_client, response_header2, sizeof(response_header2)); EXPECT_GT(readlen, 0); UT_Parse_RespHeaders(h2_stream_info->as_client); + + sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); + free(tapinfo->h2_stream_info); + free(tapinfo); } #endif @@ -310,49 +327,51 @@ TEST(Http2StreamParser, FrameWithJdData) action = detect_up_stream_protocol(h2_stream_info, NULL, 0, data[len], datalen[len]); } } + + sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); + free(tapinfo->h2_stream_info); + free(tapinfo); } TEST(UI_TEST_INFLATE_GZIP, inflate_01) { char *uncompr = NULL; - struct tfe_h2_payload body; int ret = 0, uncompr_len = 0; - - memset(&body, 0, sizeof(struct tfe_h2_payload)); - - ret = inflate_read(ut_gip_01, sizeof(ut_gip_01), &uncompr, &uncompr_len, &(body.inflate), 2); + struct z_stream_st *inflate = NULL; + ret = inflate_read(ut_gip_01, sizeof(ut_gip_01), &uncompr, &uncompr_len, &inflate, 2); EXPECT_EQ(ret, Z_STREAM_END); EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01)); EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); + inflate_finished(&inflate); - free(uncompr); + free(uncompr); uncompr = NULL; } TEST(UI_TEST_INFLATE_GZIP, inflate_02) { - struct tfe_h2_payload body; - int ret = 0, half = 0; - int size = sizeof(ut_gip_01); + struct z_stream_st *inflate = NULL; + int ret = 0, half = 0; + int size = sizeof(ut_gip_01); half = size / 2; - body.inflate = NULL; - char *uncompr1 = NULL; int uncompr_len1 = 0; - ret = inflate_read(ut_gip_01, half, &uncompr1, &uncompr_len1, &(body.inflate), 2); + ret = inflate_read(ut_gip_01, half, &uncompr1, &uncompr_len1, &inflate, 2); EXPECT_EQ(ret, Z_OK); char *uncompr2 = NULL; int uncompr_len2 = 0; - ret = inflate_read(ut_gip_01 + half, size - half, &uncompr2, &uncompr_len2, &(body.inflate), 2); + ret = inflate_read(ut_gip_01 + half, size - half, &uncompr2, &uncompr_len2, &inflate, 2); EXPECT_EQ(ret, Z_STREAM_END); - char uncompr[1024] = {0}; - snprintf(uncompr, 1024 -1, "%s%s", uncompr1, uncompr2); + char uncompr[1024] = {0}; + memcpy(uncompr, uncompr1, uncompr_len1); + memcpy(uncompr + uncompr_len1, uncompr2, uncompr_len2); EXPECT_EQ(uncompr_len1 + uncompr_len2, sizeof(ut_ungip_01)); - //EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); + EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); - free(uncompr1); + inflate_finished(&inflate); + free(uncompr1); uncompr1 = NULL; free(uncompr2); uncompr2 = NULL; @@ -361,34 +380,34 @@ TEST(UI_TEST_INFLATE_GZIP, inflate_02) TEST(UI_TEST_DEFLATE_GZIP, deflate_01) { unsigned char *dest = NULL; - struct tfe_h2_payload body; int ret = 0, dlen = 0; struct evbuffer * buf = evbuffer_new(); int size = sizeof(ut_ungip_01); - memset(&body, 0, sizeof(struct tfe_h2_payload)); - - ret = deflate_write(&(body.deflate), ut_ungip_01, size, buf, 2, 1); + struct z_stream_st *deflate = NULL; + ret = deflate_write(&deflate, ut_ungip_01, size, buf, 2, 1); EXPECT_EQ(ret, Z_OK); + deflate_finished(&deflate); - dest = evbuffer_pullup(buf, -1); + dest = evbuffer_pullup(buf, -1); dlen = evbuffer_get_length(buf); char *uncompr = NULL; int uncompr_len = 0; - ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), 2); - EXPECT_EQ(ret, Z_STREAM_END); + struct z_stream_st *inflate = NULL; + ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, 2); + EXPECT_EQ(ret, Z_STREAM_END); EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01)); EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); - free(uncompr); + inflate_finished(&inflate); + free(uncompr); uncompr = NULL; evbuffer_free(buf); } TEST(UI_TEST_DEFLATE_GZIP, deflate_02) { - struct tfe_h2_payload body; unsigned char *dest = NULL; int ret = 0, half = 0, dlen = 0; @@ -396,32 +415,33 @@ TEST(UI_TEST_DEFLATE_GZIP, deflate_02) half = size / 2; struct evbuffer * buf = evbuffer_new(); - - memset(&body, 0, sizeof(struct tfe_h2_payload)); - - /* First frag */ - ret = deflate_write(&(body.deflate), ut_ungip_01, half, buf, 2, 0); + struct z_stream_st *deflate = NULL; + /* First frag */ + ret = deflate_write(&deflate, ut_ungip_01, half, buf, 2, 0); EXPECT_EQ(ret, Z_OK); /* Last frag */ - ret = deflate_write(&(body.deflate), ut_ungip_01 + half, size - half, buf, 2, 0); + ret = deflate_write(&deflate, ut_ungip_01 + half, size - half, buf, 2, 0); EXPECT_EQ(ret, Z_OK); /* End frag */ - ret = deflate_write(&(body.deflate), NULL, 0, buf, 2, 1); + ret = deflate_write(&deflate, NULL, 0, buf, 2, 1); EXPECT_EQ(ret, Z_OK); + deflate_finished(&deflate); - dest = evbuffer_pullup(buf, -1); + dest = evbuffer_pullup(buf, -1); dlen = evbuffer_get_length(buf); char *uncompr = NULL; int uncompr_len = 0; - ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), 2); + struct z_stream_st *inflate = NULL; + ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, 2); EXPECT_EQ(ret, Z_STREAM_END); EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01)); EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); + inflate_finished(&inflate); - free(uncompr); + free(uncompr); uncompr = NULL; evbuffer_free(buf); } @@ -429,34 +449,34 @@ TEST(UI_TEST_DEFLATE_GZIP, deflate_02) TEST(UI_TEST_DEFLATE_BR, deflate_01) { unsigned char *dest = NULL; - struct tfe_h2_payload body; int ret = 0, dlen = 0; struct evbuffer * buf = evbuffer_new(); int size = sizeof(ut_ungip_01); - memset(&body, 0, sizeof(struct tfe_h2_payload)); - - ret = deflate_write(&(body.deflate), ut_ungip_01, size, buf, HTTP2_CONTENT_ENCODING_BR, 1); + struct z_stream_st *deflate = NULL; + ret = deflate_write(&deflate, ut_ungip_01, size, buf, HTTP2_CONTENT_ENCODING_BR, 1); EXPECT_EQ(ret, Z_OK); + deflate_finished(&deflate); - dest = evbuffer_pullup(buf, -1); + dest = evbuffer_pullup(buf, -1); dlen = evbuffer_get_length(buf); char *uncompr = NULL; int uncompr_len = 0; - ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), HTTP2_CONTENT_ENCODING_BR); + struct z_stream_st *inflate = NULL; + ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, HTTP2_CONTENT_ENCODING_BR); EXPECT_EQ(ret, Z_STREAM_END); EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01)); EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); + inflate_finished(&inflate); - free(uncompr); + free(uncompr); uncompr = NULL; evbuffer_free(buf); } TEST(UI_TEST_DEFLATE_BR, deflate_02) { - struct tfe_h2_payload body; unsigned char *dest = NULL; int ret = 0, half = 0, dlen = 0; @@ -464,32 +484,33 @@ TEST(UI_TEST_DEFLATE_BR, deflate_02) half = size / 2; struct evbuffer * buf = evbuffer_new(); - - memset(&body, 0, sizeof(struct tfe_h2_payload)); - - /* First frag */ - ret = deflate_write(&(body.deflate), ut_ungip_01, half, buf, HTTP2_CONTENT_ENCODING_BR, 0); + struct z_stream_st *deflate = NULL; + /* First frag */ + ret = deflate_write(&deflate, ut_ungip_01, half, buf, HTTP2_CONTENT_ENCODING_BR, 0); EXPECT_EQ(ret, Z_OK); /* Last frag */ - ret = deflate_write(&(body.deflate), ut_ungip_01 + half, size - half, buf, HTTP2_CONTENT_ENCODING_BR, 0); + ret = deflate_write(&deflate, ut_ungip_01 + half, size - half, buf, HTTP2_CONTENT_ENCODING_BR, 0); EXPECT_EQ(ret, Z_OK); /* End frag */ - ret = deflate_write(&(body.deflate), NULL, 0, buf, HTTP2_CONTENT_ENCODING_BR, 1); + ret = deflate_write(&deflate, NULL, 0, buf, HTTP2_CONTENT_ENCODING_BR, 1); EXPECT_EQ(ret, Z_OK); + deflate_finished(&deflate); - dest = evbuffer_pullup(buf, -1); + dest = evbuffer_pullup(buf, -1); dlen = evbuffer_get_length(buf); char *uncompr = NULL; int uncompr_len = 0; - ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), HTTP2_CONTENT_ENCODING_BR); + struct z_stream_st *inflate = NULL; + ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, HTTP2_CONTENT_ENCODING_BR); EXPECT_EQ(ret, Z_STREAM_END); EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01)); EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0); + inflate_finished(&inflate); - free(uncompr); + free(uncompr); uncompr = NULL; evbuffer_free(buf); }