From: Jeff King Date: Mon, 17 Apr 2017 01:37:33 GMT Subject: Re: [PATCH] server-info: avoid calling fclose(3) twice in update_info_file() 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