This is an automated email from the ASF dual-hosted git repository.

eze pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new 006ae532ed [9.2.x] Backport: Fix memory leaks in the Healthchecks 
plugin (#12025) (#12088)
006ae532ed is described below

commit 006ae532ed9391e6ac600f52fc6a77d7515d026c
Author: Hiroaki Nakamura <[email protected]>
AuthorDate: Fri Mar 7 00:01:56 2025 +0900

    [9.2.x] Backport: Fix memory leaks in the Healthchecks plugin (#12025) 
(#12088)
    
    * Fix memory leaks in the Healthchecks plugin (#12025)
    
    * Replace nullptr to NULL in plugins/healthchecks/healthchecks.c
---
 plugins/healthchecks/healthchecks.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/plugins/healthchecks/healthchecks.c 
b/plugins/healthchecks/healthchecks.c
index 6f73b0df9b..93174e76f2 100644
--- a/plugins/healthchecks/healthchecks.c
+++ b/plugins/healthchecks/healthchecks.c
@@ -381,6 +381,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 = NULL;
+  }
+
   if (my_state->req_buffer) {
     TSIOBufferDestroy(my_state->req_buffer);
     my_state->req_buffer = NULL;
@@ -391,7 +396,11 @@ cleanup(TSCont contp, HCState *my_state)
     my_state->resp_buffer = NULL;
   }
 
-  TSVConnClose(my_state->net_vc);
+  if (my_state->net_vc) {
+    TSVConnClose(my_state->net_vc);
+    my_state->net_vc = NULL;
+  }
+
   TSfree(my_state);
   TSContDestroy(contp);
 }
@@ -420,11 +429,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");
   }
@@ -451,6 +463,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");
   }

Reply via email to