Skip to content

Commit 590b636

Browse files
peffgitster
authored andcommitted
hash-object: fix descriptor leak with --literally
In hash_object(), we open a descriptor for each file to hash (whether we got the filename from the command line or --stdin-paths), but never close it. For the traditional code path, which feeds the result to index_fd(), this is OK; it closes the descriptor for us. But 5ba9a93 (hash-object: add --literally option, 2014-09-11) added a second code path, which does not close the descriptor. There we need to do so ourselves. You can see the problem in a clone of git.git like this: $ git ls-files -s | grep ^100644 | cut -f2 | git hash-object --stdin-paths --literally >/dev/null fatal: could not open 'builtin/var.c' for reading: Too many open files After this patch, it completes successfully. I didn't bother with a test, as it's a pain to deal with descriptor limits portably, and the fix is so trivial. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37ed7bf commit 590b636

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

builtin/hash-object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig
2727
else
2828
ret = write_object_file_literally(buf.buf, buf.len, type, oid,
2929
flags);
30+
close(fd);
3031
strbuf_release(&buf);
3132
return ret;
3233
}

0 commit comments

Comments
 (0)