diff mbox series

[2/2] FIX memory leak in one branch

Message ID a7c81f7e114fc8854436e2ca1fccb4c968653317.1706105064.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series FIX: use utf8_strnwidth for line_prefix in diff.c | expand

Commit Message

Md Isfarul Haque Jan. 24, 2024, 2:04 p.m. UTC
From: Md Isfarul Haque <isfarul.876@gmail.com>

Signed-off-by: Md Isfarul Haque <isfarul.876@gmail.com>
---
 diff.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Junio C Hamano Jan. 24, 2024, 8:11 p.m. UTC | #1
"Md Isfarul Haque via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Md Isfarul Haque <isfarul.876@gmail.com>
>
> Signed-off-by: Md Isfarul Haque <isfarul.876@gmail.com>
> ---
>  diff.c | 1 +
>  1 file changed, 1 insertion(+)

We do not need to see that you are just as human as other developers
and are prone to make mistakes that you need to fix it in a
follow-up.  In other words, please do not introduce a bug in [1/2]
only to be fixed in [2/2].  By squashing these two patches into one,
you can pretend as if you are a perfect developer and never leaked
memory ;-).

> diff --git a/diff.c b/diff.c
> index e3223b8ce5b..9fa00103a6b 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -2309,6 +2309,7 @@ const struct strbuf *diff_line_prefix_buf(struct diff_options *opt)
>  		msgbuf->alloc = 1;
>  	}
>  	else {
> +		free(msgbuf);
>  		msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
>  	}
>  	return msgbuf;

But as I said, I do not see a need for this helper function in the
first place, so...
diff mbox series

Patch

diff --git a/diff.c b/diff.c
index e3223b8ce5b..9fa00103a6b 100644
--- a/diff.c
+++ b/diff.c
@@ -2309,6 +2309,7 @@  const struct strbuf *diff_line_prefix_buf(struct diff_options *opt)
 		msgbuf->alloc = 1;
 	}
 	else {
+		free(msgbuf);
 		msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
 	}
 	return msgbuf;