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