git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] reflog: close leak of reflog expire entry

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Jul 9, 2025, 21:49 UTC
Message-ID
<20250709-jk-fix-leak-reflog-expire-config-v1-1-34d5461cf8f5@gmail.com>
From: Jacob Keller <jacob.keller@gmail.com>

find_cfg_ent() allocates a struct reflog_expire_entry_option via FLEX_ALLOC_MEM and returns its pointer to reflog_expire_config(). The function exits without freeing the memory:

Direct leak of 39 byte(s) in 1 object(s) allocated from:
    #0 0x7ff975ee6883 in calloc (/lib64/libasan.so.8+0xe6883)
    #1 0x0000010edada in xcalloc ../wrapper.c:154
    #2 0x000000df0898 in find_cfg_ent ../reflog.c:28
    #3 0x000000df0898 in reflog_expire_config ../reflog.c:70
    #4 0x00000095c451 in configset_iter ../config.c:2116
    #5 0x0000006d29e7 in git_config ../config.h:724
    #6 0x0000006d29e7 in cmd_reflog_expire ../builtin/reflog.c:205
    #7 0x0000006d504c in cmd_reflog ../builtin/reflog.c:419
    #8 0x0000007e4054 in run_builtin ../git.c:480
    #9 0x0000007e4054 in handle_builtin ../git.c:746
    #10 0x0000007e8a35 in run_argv ../git.c:813
    #11 0x0000007e8a35 in cmd_main ../git.c:953
    #12 0x000000441e8f in main ../common-main.c:9
    #13 0x7ff9754115f4 in __libc_start_call_main (/lib64/libc.so.6+0x35f4)
    #14 0x7ff9754116a7 in __libc_start_main@@GLIBC_2.34 (/lib64/libc.so.6+0x36a7)
    #15 0x000000444184 in _start (/home/jekeller/libexec/git-core/git+0x444184)

Close this leak by freeing the entry pointer on exit of the reflog_expire_config() function. This frees both the entry structure and its embedded pattern array thanks to the use of FLEX_ALLOC_MEM.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 reflog.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/reflog.c b/reflog.c
index 15d81ebea978..43647eaf89eb 100644
--- a/reflog.c
+++ b/reflog.c
@@ -78,6 +78,9 @@ int reflog_expire_config(const char *var, const char *value,
 		ent->expire_unreachable = expire;
 		break;
 	}
+
+	free(ent);
+
 	return 0;
 }
 

---
base-commit: a30f80fde927d70950b3b4d1820813480968fb0d
change-id: 20250709-jk-fix-leak-reflog-expire-config-712ca6dc685a

Best regards,
--  
Jacob Keller <jacob.keller@gmail.com>
Next: Jeff King
Message 1 of 3 in “reflog: close leak of reflog expire entry”
  1. reflog: close leak of reflog expire entryJacob Keller, Jul 9, 2025
  2. Jeff KingJul 9, 2025
  3. Keller, Jacob EJul 9, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.