fsmonitor: fix leak of warning message

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>

Jeff King committed Oct 10, 2022 at 20:42 UTC c4f94907902f18d80a78ee19983d0d02932154d7
1 file changed +3 -1
fsmonitor.c
+3 -1
@@ -309,8 +309,10 @@ void refresh_fsmonitor(struct index_state *istate)
309 enum fsmonitor_reason reason = fsm_settings__get_reason(r);
310
311 if (!warn_once && reason > FSMONITOR_REASON_OK) {
312 + char *msg = fsm_settings__get_incompatible_msg(r, reason);
313 warn_once = 1;
313 - warning("%s", fsm_settings__get_incompatible_msg(r, reason));
314 + warning("%s", msg);
315 + free(msg);
316 }
317
318 if (fsm_mode <= FSMONITOR_MODE_DISABLED ||