From b4db7c3855c22c5b6cfcbabffd760e1808144e2e Mon Sep 17 00:00:00 2001
From: dormando <dormando@rydia.net>
Date: Sun, 10 Mar 2024 10:17:24 -0700
Subject: [PATCH] proxy: fix leak in config reload

- config reload loads the code from disk, then dumps it into an internal
  binary blob
- that binary blob is loaded from memory into each worker thread
- that temporary blob wasn't being freed

if you have large initial lua and reload every second for hours on end
you'd leak a few megs of ram

---
 proxy_config.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/proxy_config.c b/proxy_config.c
index cfe43b1..65e7e3a 100644
--- a/proxy_config.c
+++ b/proxy_config.c
@@ -240,6 +240,12 @@ int proxy_load_config(void *arg) {
     db->buf = malloc(db->size);
     lua_dump(L, _dump_helper, db, 0);
     // 0 means no error.
+    if (ctx->proxy_code) {
+        struct _dumpbuf *old = ctx->proxy_code;
+        free(old->buf);
+        free(old);
+        ctx->proxy_code = NULL;
+    }
     ctx->proxy_code = db;
 
     // now we complete the data load by calling the function.
-- 
2.27.0

