git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] pack-revindex.c: don't close unopened file descriptors

From
Jeff King <peff@peff.net>
Date
Feb 26, 2021, 17:55 UTC
Message-ID
<YDk1/y1CmsPYC88C@coredump.intra.peff.net>
In-Reply-To
<34c017296a7c5fe4a2ea70f8a0b2d8586b34a4dc.1614357030.git.me@ttaylorr.com>
On Fri, Feb 26, 2021 at 11:31:02AM -0500, Taylor Blau wrote:
Show 10 quoted lines
> When opening a reverse index, load_revindex_from_disk() jumps to the
> 'cleanup' label in case something goes wrong: the reverse index had the
> wrong size, an unrecognized version, or similar.
> 
> It also jumps to this label when the reverse index couldn't be opened in
> the first place, which will cause an error with the unguarded close()
> call in the label.
> 
> Guard this call with "if (fd >= 0)" to make sure that we have a valid
> file descriptor to close before attempting to close it.

Makes sense. Running close(-1) wasn't really hurting much in practice, but it's cleaner not to do so.

This would go on top of tb/pack-revindex-on-disk.
> Dscho mentioned this to me privately when reviewing Coverity results for
> -rc0. This one is legitimate, and the fix is easy enough, too.

I'm excited that we might get Coverity results again. There were a lot of false positives, but I found its signal-to-noise ratio higher than almost every other static analysis tool I've looked at.

-Peff
Previous: Taylor BlauNext: Johannes Schindelin
Message 2 of 4 in “pack-revindex.c: don't close unopened file descriptors”
  1. pack-revindex.c: don't close unopened file descriptorsTaylor Blau, Feb 26, 2021
  2. Jeff KingFeb 26, 2021
  3. Johannes SchindelinMar 1, 2021
  4. Junio C HamanoFeb 26, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.