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