diff --git a/ci/asan_leak_suppression/regression.txt b/ci/asan_leak_suppression/regression.txt index b3dfcf83631..3bcd60f553a 100644 --- a/ci/asan_leak_suppression/regression.txt +++ b/ci/asan_leak_suppression/regression.txt @@ -2,7 +2,6 @@ leak:RegressionTest_PARENTSELECTION leak:ParentConfig::reconfigure leak:RegressionTest_SDK_API_TSHttpConnectIntercept leak:RegressionTest_SDK_API_TSHttpConnectServerIntercept -leak:make_log_host leak:ReRegressionSM::clone leak:RegressionTest_ram_cache leak:RegressionTest_HttpTransact_is_request_valid @@ -11,9 +10,7 @@ leak:MakeTextLogFormat leak:RegressionTest_HttpTransact_handle_trace_and_options_requests leak:CRYPTO_malloc leak:RegressionTest_SDK_API_TSMgmtGet -leak:RegressionTest_Cache_vol leak:RegressionTest_SDK_API_TSCache -leak:RegressionTest_Hdrs leak:RegressionTest_SDK_API_TSPortDescriptor leak:RegressionTest_HostDBProcessor leak:RegressionTest_DNS diff --git a/ci/asan_leak_suppression/unit_tests.txt b/ci/asan_leak_suppression/unit_tests.txt index da34e83c615..a553604f1bf 100644 --- a/ci/asan_leak_suppression/unit_tests.txt +++ b/ci/asan_leak_suppression/unit_tests.txt @@ -1,10 +1,4 @@ -# leaks in test_X509HostnameValidator -leak:libcrypto.so.1.1 -# for OpenSSL 1.0.2: -leak:CRYPTO_malloc -leak:CRYPTO_realloc -leak:ConsCell -# PR#10295 -leak:pcre_jit_stack_alloc -# PR#10541 +# marshal_hdr in test_http_hdr_print_and_copy_aux is intentionally +# not destroyed because it holds a reference to a stack-allocated +# TestRefCountObj whose free() override calls exit(1). leak:test_http_hdr_print_and_copy_aux diff --git a/src/proxy/hdrs/unit_tests/test_Hdrs.cc b/src/proxy/hdrs/unit_tests/test_Hdrs.cc index fef0166d499..598e4e61894 100644 --- a/src/proxy/hdrs/unit_tests/test_Hdrs.cc +++ b/src/proxy/hdrs/unit_tests/test_Hdrs.cc @@ -183,6 +183,13 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon HTTPHdr copy1; HTTPHdr copy2; + ts::PostScript cleanup([&]() -> void { + req_hdr.destroy(); + resp_hdr.destroy(); + copy1.destroy(); + copy2.destroy(); + }); + HTTPParser parser; const char *start; const char *end; @@ -236,15 +243,11 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon copy1.create(HTTPType::REQUEST); copy1.copy(&req_hdr); comp_str = comp_http_hdr(&req_hdr, ©1); - if (comp_str) { - goto done; - } - copy2.create(HTTPType::RESPONSE); - copy2.copy(&resp_hdr); - comp_str = comp_http_hdr(&resp_hdr, ©2); - if (comp_str) { - goto done; + if (!comp_str) { + copy2.create(HTTPType::RESPONSE); + copy2.copy(&resp_hdr); + comp_str = comp_http_hdr(&resp_hdr, ©2); } // The APIs for copying headers uses memcpy() which can be unsafe for @@ -252,32 +255,24 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon // created in the first place honestly, since nothing else does this. /*** (4) Gender bending copying ***/ - copy1.copy(&resp_hdr); - comp_str = comp_http_hdr(&resp_hdr, ©1); - if (comp_str) { - goto done; + if (!comp_str) { + copy1.copy(&resp_hdr); + comp_str = comp_http_hdr(&resp_hdr, ©1); } - copy2.copy(&req_hdr); - comp_str = comp_http_hdr(&req_hdr, ©2); - if (comp_str) { - goto done; + if (!comp_str) { + copy2.copy(&req_hdr); + comp_str = comp_http_hdr(&req_hdr, ©2); } -done: - req_hdr.destroy(); - resp_hdr.destroy(); - copy1.destroy(); - copy2.destroy(); - if (comp_str) { printf("FAILED: (test #%d) copy & compare: %s\n", testnum, comp_str); printf("REQ:\n[%.*s]\n", static_cast(strlen(request)), request); printf("RESP :\n[%.*s]\n", static_cast(strlen(response)), response); return (0); - } else { - return (1); } + + return (1); } int @@ -379,10 +374,16 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r { ParseResult err; HTTPHdr hdr; + HTTPHdr new_hdr; HTTPParser parser; const char *start; const char *end; + ts::PostScript cleanup([&]() -> void { + hdr.destroy(); + new_hdr.destroy(); + }); + char prt_buf[2048]; int prt_bufsize = sizeof(prt_buf); int prt_bufindex, prt_dumpoffset, prt_ret; @@ -416,7 +417,7 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r } /*** (2) copy the request header ***/ - HTTPHdr new_hdr, marshal_hdr; + HTTPHdr marshal_hdr; TestRefCountObj ref; // Pretend to pin this object with a refcount. @@ -524,9 +525,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r return (0); } - hdr.destroy(); - new_hdr.destroy(); - if (test_http_hdr_copy_over_aux(testnum, request, response) == 0) { return 0; }