Skip to content

Commit

Permalink
promise: fix memory leaks
Browse files Browse the repository at this point in the history
Several memory leaks were detected. I fixed these by freeing the promise
after use.

Signed-off-by: Philip Peterson <[email protected]>
  • Loading branch information
philip-peterson committed Feb 16, 2024
1 parent 970c2ff commit 9086541
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,7 @@ static void find_header(struct apply_state *state,
}

git_hdr_len = parse_git_diff_header_promise->result.success_result;
promise_release(parse_git_diff_header_promise);
if (git_hdr_len <= len)
continue;
*hdrsize = git_hdr_len;
Expand Down Expand Up @@ -2161,6 +2162,7 @@ static void parse_chunk(struct apply_state *state, char *buffer, unsigned long s
}

offset = find_header_promise->result.success_result;
promise_release(find_header_promise);

if (offset < 0) {
PROMISE_SUCCEED(return_promise, offset);
Expand Down Expand Up @@ -4798,13 +4800,16 @@ static int apply_patch(struct apply_state *state,
free_patch(patch);
if (nr == -128) {
error("\n\t%s", parse_chunk_promise->result.failure_result.message.buf);
promise_release(parse_chunk_promise);
res = -128;
goto end;
}
break;
}

nr = parse_chunk_promise->result.success_result;
promise_release(parse_chunk_promise);

if (state->apply_in_reverse)
reverse_patches(patch);
if (use_patch(state, patch)) {
Expand Down
2 changes: 1 addition & 1 deletion promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void promise_release(struct promise_t *promise);
strbuf_insertf(&src->result.failure_result.message, 0, __VA_ARGS__); \
} \
promise_reject(dst, src->result.failure_result.status, "%s", src->result.failure_result.message.buf); \
strbuf_release(&src->result.failure_result.message); \
promise_release(src); \
return; \
} while (0)

Expand Down
2 changes: 2 additions & 0 deletions range-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ static int read_patches(const char *range, struct string_list *list,
orig_len, line);
FREE_AND_NULL(util);
string_list_clear(list, 1);
promise_release(parse_git_diff_header_promise);
goto cleanup;
}
len = parse_git_diff_header_promise->result.success_result;
promise_release(parse_git_diff_header_promise);
strbuf_addstr(&buf, " ## ");
if (patch.is_new > 0)
strbuf_addf(&buf, "%s (new)", patch.new_name);
Expand Down

0 comments on commit 9086541

Please sign in to comment.