[PATCH] fix memory leak in parse_object when check_sha1_signature fails

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] fix memory leak in parse_object when check_sha1_signature fails

From: Carlos Rica <hidden>
Date: 2016-06-15 22:43:12

When check_sha1_signature fails, program is not terminated:
it prints an error message and returns NULL, so the
buffer returned by read_sha1_file should be freed before.

Signed-off-by: Carlos Rica <redacted>
---
 object.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/object.c b/object.c
index 78a44a6..ccd7dd7 100644
--- a/object.c
+++ b/object.c
@@ -185,6 +185,7 @@ struct object *parse_object(const unsigned char *sha1)
 	if (buffer) {
 		struct object *obj;
 		if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0) {
+			free(buffer);
 			error("sha1 mismatch %s\n", sha1_to_hex(sha1));
 			return NULL;
 		}
-- 
1.5.0

Re: [PATCH] fix memory leak in parse_object when check_sha1_signature fails

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:43:12

Carlos Rica [off-list ref] wrote:
When check_sha1_signature fails, program is not terminated:
it prints an error message and returns NULL, so the
buffer returned by read_sha1_file should be freed before.
...
		if (check_sha1_signature(sha1, buffer, size, typename(type)) 
		< 0) {
...

gmail strikes again.  The above line is wrapped, which means your
patch is whitespace damaged and won't apply properly.

-- 
Shawn.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help