Skip to contentSkip to conversation

apply: plug strbuf leak

PATCH In review Junio C Hamano 1 participant 2 messages May 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 apply: plug strbuf leak

Depending on how read_patch_file() fails, it may already have read many bytes into the supplied strbuf. Either the caller or the callee should release the strbuf.

Here we choose to make the sole caller of the function responsible for releasing it, as it makes the error handling slightly simpler.

---
 apply.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
apply.c +3 -1
index 4aa1694cfa..0167902325 100644
@@ -4881,8 +4881,10 @@ static int apply_patch(struct apply_state *state,
 
 	state->patch_input_file = filename;
 	state->linenr = 1;
-	if (read_patch_file(&buf, fd) < 0)
+	if (read_patch_file(&buf, fd) < 0) {
+		strbuf_release(&buf);
 		return -128;
+	}
 	offset = 0;
 	while (offset < buf.len) {
 		struct patch *patch;
Signature · 1 line
2.54.0-398-ga4b2d32071
#1 lore raw
Quoted 17 lines · Junio C Hamano

Depending on how read_patch_file() fails, it may already have read many bytes into the supplied strbuf. Either the caller or the callee should release the strbuf.

Here we choose to make the sole caller of the function responsible for releasing it, as it makes the error handling slightly simpler.

---
 apply.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
apply.c +0 -0
index 4aa1694cfa..0167902325 100644

apply.c static int apply_patch(struct apply_state *state, · line 4887

Quoted 8 lines
apply.c +3 -1
@@ -4881,8 +4881,10 @@ static int apply_patch(struct apply_state *state,
 
 	state->patch_input_file = filename;
 	state->linenr = 1;
-	if (read_patch_file(&buf, fd) < 0)
+	if (read_patch_file(&buf, fd) < 0) {
+		strbuf_release(&buf);
 		return -128;
+	}

Ah, my mistake. This was one of the two "oh, we found longstanding issues immediately after enabling EXPENSIVE tests on" fixes Peff already fixed for us.

Quoted 3 lines
apply.c +0 -0
 	offset = 0;
 	while (offset < buf.len) {
 		struct patch *patch;