Skip to contentSkip to conversation

object-file: fix leak on conversion failure

PATCH In review Eric Wong 3 participants 3 messages Jun 22, 2024 – Jun 24, 2024

lore
Share & tools
lore

Eric Wong

author
#0 lore raw

PATCH 1/1 object-file: fix leak on conversion failure

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.

---
 object-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
object-file.c +1 -1
index d3cf4b8b2e..00c8f1039b 100644
@@ -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);
 		}
#1 lore raw
Quoted 4 lines · Eric Wong

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.

object-file.c static int oid_object_info_convert(struct repository *r, · line 1716

Quoted 7 lines

ret = convert_object_file(&outbuf,
the_hash_algo, input_algo, content, size, type, !do_die);

object-file.c +1 -1
+			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

#2 lore raw
Quoted 9 lines · Derrick Stolee
Quoted 4 lines · Eric Wong

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.

Quoted 11 lines

object-file.c static int oid_object_info_convert(struct repository *r, · line 1716

Quoted 7 lines

ret = convert_object_file(&outbuf,
the_hash_algo, input_algo, content, size, type, !do_die);

object-file.c +1 -1
+			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.