Thread (3 messages) 3 messages, 2 authors, 2025-07-09
STALE385d

[PATCH] reflog: close leak of reflog expire entry

From: Jacob Keller <jacob.e.keller@intel.com>
Date: 2025-07-09 21:49:55
Subsystem: the rest · Maintainer: Linus Torvalds

From: Jacob Keller <redacted>

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 <redacted>
---
 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 [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help