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

Re: [PATCH] server-info: avoid calling fclose(3) twice in update_info_file()

From
Jeff King <peff@peff.net>
Date
Apr 17, 2017, 01:37 UTC
Message-ID
<20170417013733.ga362sz67n7vbt32@sigill.intra.peff.net>
In-Reply-To
<137d732f-7a23-8a8a-9f2b-7f16bb361c5a@web.de>
On Sun, Apr 16, 2017 at 06:55:58PM +0200, René Scharfe wrote:
> If an error occurs when or after closing the stream we call fclose(3)
> again in the error handler.  The second call can exhibit undefined
> behavior, so make sure to call fclose(3) at most once.
Yikes. Good catch.
> Also avoid
> calling close(2) after fd has been successfully associated with the
> stream, as fclose(3) has become responsible for doing that beyond
> this point.

Yeah, the "else if" in the error-code was supposed to handle that, but it comes back when you fix the double-fclose by setting fp to NULL.

So the whole thing looks good to me. Thanks for cleaning up my mess.
-Peff
Previous: René Scharfe
Message 2 of 2 in “server-info: avoid calling fclose(3) twice in update_info_file()”
  1. server-info: avoid calling fclose(3) twice in update_info_file()René Scharfe, Apr 16, 2017
  2. Jeff KingApr 17, 2017

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.