git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] object-file: fix leak on conversion failure
@ 2024-06-22  4:36 Eric Wong
  2024-06-23 16:34 ` Derrick Stolee
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2024-06-22  4:36 UTC (permalink / raw)
  To: Eric W. Biederman, git

I'm not sure exactly how to trigger the leak, but it seems fairly
obvious that the `content' buffer should be freed even if
convert_object_file() fails.  Noticed while working in this area
on unrelated things.

Signed-off-by: Eric Wong <e@80x24.org>
---
 object-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/object-file.c b/object-file.c
index d3cf4b8b2e..00c8f1039b 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1711,9 +1711,9 @@ static int oid_object_info_convert(struct repository *r,
 			ret = convert_object_file(&outbuf,
 						  the_hash_algo, input_algo,
 						  content, size, type, !do_die);
+			free(content);
 			if (ret == -1)
 				return -1;
-			free(content);
 			size = outbuf.len;
 			content = strbuf_detach(&outbuf, NULL);
 		}

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] object-file: fix leak on conversion failure
  2024-06-22  4:36 [PATCH] object-file: fix leak on conversion failure Eric Wong
@ 2024-06-23 16:34 ` Derrick Stolee
  2024-06-24 16:08   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Derrick Stolee @ 2024-06-23 16:34 UTC (permalink / raw)
  To: Eric Wong, Eric W. Biederman, git

On 6/22/24 12:36 AM, Eric Wong wrote:
> I'm not sure exactly how to trigger the leak, but it seems fairly
> obvious that the `content' buffer should be freed even if
> convert_object_file() fails.  Noticed while working in this area
> on unrelated things.

Definitely a good thing to include, even if it is unlikely to
be hit frequently in common scenarios.

>   			ret = convert_object_file(&outbuf,
>   						  the_hash_algo, input_algo,
>   						  content, size, type, !do_die);
> +			free(content);
>   			if (ret == -1)
>   				return -1;
> -			free(content);

I looked at the context of this function to see that 'content'
was local to the method, so was not "owned" by something outside
of the method that might expect to reuse the buffer on failure.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] object-file: fix leak on conversion failure
  2024-06-23 16:34 ` Derrick Stolee
@ 2024-06-24 16:08   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2024-06-24 16:08 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Eric Wong, Eric W. Biederman, git

Derrick Stolee <stolee@gmail.com> writes:

> On 6/22/24 12:36 AM, Eric Wong wrote:
>> I'm not sure exactly how to trigger the leak, but it seems fairly
>> obvious that the `content' buffer should be freed even if
>> convert_object_file() fails.  Noticed while working in this area
>> on unrelated things.
>
> Definitely a good thing to include, even if it is unlikely to
> be hit frequently in common scenarios.
>
>>   			ret = convert_object_file(&outbuf,
>>   						  the_hash_algo, input_algo,
>>   						  content, size, type, !do_die);
>> +			free(content);
>>   			if (ret == -1)
>>   				return -1;
>> -			free(content);
>
> I looked at the context of this function to see that 'content'
> was local to the method, so was not "owned" by something outside
> of the method that might expect to reuse the buffer on failure.

Thanks, both.

Will queue.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-24 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-22  4:36 [PATCH] object-file: fix leak on conversion failure Eric Wong
2024-06-23 16:34 ` Derrick Stolee
2024-06-24 16:08   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).