This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 4b13b1489134013d0d3f37a358885c79da5306d8 Author: Hiroaki Nakamura <[email protected]> AuthorDate: Wed Feb 12 13:21:58 2025 +0900 Fix memory leaks in the Healthchecks plugin (#12025) (cherry picked from commit 769057c4f3cb9db1657efefa286231e40885adc7) --- plugins/healthchecks/healthchecks.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/healthchecks/healthchecks.cc b/plugins/healthchecks/healthchecks.cc index 23c45e7ad3..c11a543662 100644 --- a/plugins/healthchecks/healthchecks.cc +++ b/plugins/healthchecks/healthchecks.cc @@ -384,6 +384,11 @@ parse_configs(const char *fname) static void cleanup(TSCont contp, HCState *my_state) { + if (my_state->resp_reader) { + TSIOBufferReaderFree(my_state->resp_reader); + my_state->resp_reader = nullptr; + } + if (my_state->req_buffer) { TSIOBufferDestroy(my_state->req_buffer); my_state->req_buffer = nullptr; @@ -394,7 +399,11 @@ cleanup(TSCont contp, HCState *my_state) my_state->resp_buffer = nullptr; } - TSVConnClose(my_state->net_vc); + if (my_state->net_vc) { + TSVConnClose(my_state->net_vc); + my_state->net_vc = nullptr; + } + TSfree(my_state); TSContDestroy(contp); } @@ -423,11 +432,14 @@ hc_process_read(TSCont contp, TSEvent event, HCState *my_state) my_state->write_vio = TSVConnWrite(my_state->net_vc, contp, my_state->resp_reader, INT64_MAX); } else if (event == TS_EVENT_ERROR) { TSError("[healthchecks] hc_process_read: Received TS_EVENT_ERROR"); + cleanup(contp, my_state); } else if (event == TS_EVENT_VCONN_EOS) { - /* client may end the connection, simply return */ + /* client may end the connection, clean up and return */ + cleanup(contp, my_state); return; } else if (event == TS_EVENT_NET_ACCEPT_FAILED) { TSError("[healthchecks] hc_process_read: Received TS_EVENT_NET_ACCEPT_FAILED"); + cleanup(contp, my_state); } else { TSReleaseAssert(!"Unexpected Event"); } @@ -454,6 +466,7 @@ hc_process_write(TSCont contp, TSEvent event, HCState *my_state) cleanup(contp, my_state); } else if (event == TS_EVENT_ERROR) { TSError("[healthchecks] hc_process_write: Received TS_EVENT_ERROR"); + cleanup(contp, my_state); } else { TSReleaseAssert(!"Unexpected Event"); }
