Thread View: linux.kernel.git
1 messages
1 total messages
Started by Junio C Hamano
Tue, 24 Nov 2026 22:04
Re: [PATCH 3/6] packfile: inline `open_packed_git_1()`
Author: Junio C Hamano
Date: Tue, 24 Nov 2026 22:04
Date: Tue, 24 Nov 2026 22:04
53 lines
14409 bytes
14409 bytes
Patrick Steinhardt <ps@pks.im> writes:
> The function `open_packed_git()` is responsible for opening a packfile.
> The majority of work is not performed by it though, but instead by its
> `_1()` sibling. But this sibling really only exists because we thought
> it too hard to handle errors properly and close the packfile's file
> descriptor on an error path. So `_1()` doesn't handle those, and instead
> defers to its only caller to close the file descriptor in the error path
> again.
>
> Fix this design smell by introducing a common exit path that knows to
> close the file descriptor on error. This allows us to inline the call to
> `open_packed_git_1()`.
I agree that this makes the descriptor ownership much easier to follow.
It is not just the call but the entire function got inlined, but I
shouldn't split hairs ;-)
> @@ -510,55 +509,81 @@ static int open_packed_git_1(struct packed_git *p)
> ; /* nothing */
>
> p->pack_fd = git_open(p->pack_name);
> - if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
> - return -1;
> + if (p->pack_fd < 0 || fstat(p->pack_fd, &st)) {
> + ret = -1;
> + goto out;
> + }
> pack_open_fds++;
There may be a mismatch in pack_open_fds accounting. If git_open()
succeeds (so p->pack_fd >= 0) and fstat() fails, we jump to 'out:'
before incrementing pack_open_fds.
> +out:
> + if (ret < 0)
> + packfile_close_fd(p);
> + return ret;
> }
close_pack_fd() (now called packfile_close_fd()) closes p->pack_fd
whenever p->pack_fd >= 0 and decrements pack_open_fds, which may
underflow to UINT_MAX if the ftat() failed because of this?
May not be a new bug (we used to leave the p->pack_fd open without
nobody closing instead, so we may not have underflown but leaked file
descriptor instead), but since you are touching around the area, we may
want to fix it as well.
Other than that, looking good.
Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads