]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: fix leak of warning message
authorJeff King <peff@peff.net>
Tue, 11 Oct 2022 00:42:38 +0000 (20:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Oct 2022 05:16:56 +0000 (22:16 -0700)
The fsm_settings__get_incompatible_msg() function returns an allocated
string.  So we can't pass its result directly to warning(); we must hold
on to the pointer and free it to avoid a leak.

The leak here is small and fixed size, but Coverity complained, and
presumably SANITIZE=leaks would eventually.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsmonitor.c

index 540736b39fd105f103c1a94057d48021ea4ecd4a..08af00c73872d2c3516d6bb419c099e058fd6345 100644 (file)
@@ -309,8 +309,10 @@ void refresh_fsmonitor(struct index_state *istate)
        enum fsmonitor_reason reason = fsm_settings__get_reason(r);
 
        if (!warn_once && reason > FSMONITOR_REASON_OK) {
+               char *msg = fsm_settings__get_incompatible_msg(r, reason);
                warn_once = 1;
-               warning("%s", fsm_settings__get_incompatible_msg(r, reason));
+               warning("%s", msg);
+               free(msg);
        }
 
        if (fsm_mode <= FSMONITOR_MODE_DISABLED ||