File 0002-Merge-pull-request-5441-from-HofiOne-fix-mem-leaks.patch of Package syslog-ng

From 44b26512a7bf9c78f07ea5db4b0dcf10f2475052 Mon Sep 17 00:00:00 2001
From: Hofi <hofione@gmail.com>
Date: Tue, 26 Aug 2025 15:34:52 +0200
Subject: [PATCH 2/4] Merge pull request #5441 from HofiOne/fix-mem-leaks

stats-exporter: fixed various leaks
(cherry picked from commit 4a1c3f00cdd93f7c82c3ce45b30fcbc7d705c056)
---
 lib/logproto/logproto-buffered-server.c               | 2 ++
 lib/logproto/logproto-http-scraper-responder-server.c | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/lib/logproto/logproto-buffered-server.c b/lib/logproto/logproto-buffered-server.c
index eab78afe4..35c3555d0 100644
--- a/lib/logproto/logproto-buffered-server.c
+++ b/lib/logproto/logproto-buffered-server.c
@@ -572,6 +572,8 @@ error:
       else
         {
           self->persist_state = NULL;
+          if (self->state1)
+            g_free(self->state1);
           self->state1 = new_state;
         }
     }
diff --git a/lib/logproto/logproto-http-scraper-responder-server.c b/lib/logproto/logproto-http-scraper-responder-server.c
index 7f3f13cd2..ee8e6ecf9 100644
--- a/lib/logproto/logproto-http-scraper-responder-server.c
+++ b/lib/logproto/logproto-http-scraper-responder-server.c
@@ -34,6 +34,7 @@
 static LogProtoHTTPScraperResponder *single_instance;
 static time_t last_scrape_request_time;
 
+// FIXME: cleanup mutex on program exit
 static inline GMutex *
 _mutex(void)
 {
@@ -141,6 +142,8 @@ _log_proto_http_scraper_responder_server_free(LogProtoServer *s)
   LogProtoHTTPScraperResponder *self = (LogProtoHTTPScraperResponder *)s;
   if (self->options->single_instance)
     single_instance = NULL;
+  // The base LogProtoHTTPServer has no overridden free_fn, so we call its base LogProtoTextServer free directly
+  log_proto_text_server_free(s);
   g_mutex_unlock(_mutex());
 }
 
@@ -227,6 +230,8 @@ log_proto_http_scraper_responder_options_destroy(LogProtoServerOptionsStorage *o
   LogProtoHTTPScraperResponderOptions *options = &((LogProtoHTTPScraperResponderOptionsStorage *)options_storage)->super;
 
   log_proto_http_server_options_destroy(options_storage);
+  g_free(options->scraper_request_hdr_pattern);
+  options->scraper_request_hdr_pattern = NULL;
   g_free(options->stat_query);
   options->stat_query = NULL;
   g_free(options->stat_format);
-- 
2.51.0

openSUSE Build Service is sponsored by