Re: What's cooking in git.git (Oct 2022, #03; Mon, 10)
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 11, 2022, 05:21 UTC
- Message-ID
- <xmqqczazx7dn.fsf@gitster.g>
- In-Reply-To
- <Y0S7/jA5tNeoQ2Hm@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 16 quoted lines
> There's a tiny leak in this one. Here's a fix that can go on top. > > -- >8 -- > Subject: [PATCH] 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> > --- > fsmonitor.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-)
Is there anybody else who is reading Coverity reports, I wonder. This one is a clear positive.
Thanks.
Show 16 quoted lines
> 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 ||