From: Jeff King Date: Tue, 11 Oct 2022 00:42:38 +0000 (-0400) Subject: fsmonitor: fix leak of warning message X-Git-Tag: v2.39.0-rc0~112^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4f94907902f18d80a78ee19983d0d02932154d7;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/fsmonitor.c b/fsmonitor.c index 540736b39f..08af00c738 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -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 ||