Skip to content

Commit 0cd162b

Browse files
authored
Merge pull request libgit2#4008 from pks-t/pks/sortedcache-fd-leak
sortedcache: plug leaked file descriptor
2 parents 1db3035 + 613381f commit 0cd162b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/patch_parse.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,10 @@ git_patch_parse_ctx *git_patch_parse_ctx_init(
10141014
return NULL;
10151015

10161016
if (content_len) {
1017-
if ((ctx->content = git__malloc(content_len)) == NULL)
1017+
if ((ctx->content = git__malloc(content_len)) == NULL) {
1018+
git__free(ctx);
10181019
return NULL;
1020+
}
10191021

10201022
memcpy((char *)ctx->content, content, content_len);
10211023
}

src/sortedcache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ int git_sortedcache_lockandload(git_sortedcache *sc, git_buf *buf)
216216
if (p_fstat(fd, &st) < 0) {
217217
giterr_set(GITERR_OS, "failed to stat file");
218218
error = -1;
219+
(void)p_close(fd);
219220
goto unlock;
220221
}
221222

0 commit comments

Comments
 (0)