Coverity fix: USE_AFTER_FREE CID:438
authorNelson Ferreira <nelson.ferreira@ieee.org>
Mon, 10 Oct 2011 13:51:43 +0000 (09:51 -0400)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Mon, 10 Oct 2011 13:51:43 +0000 (09:51 -0400)
* src/sysdep.c (sys_fclose): loop with close on fd, not fclose

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
src/sysdep.c

index fa74c2d..e4844df 100644 (file)
@@ -2454,9 +2454,11 @@ FILE *sys_fopen(const char *path, const char *type)
 int sys_fclose(FILE * stream)
 {
 #ifdef INTERRUPTIBLE_CLOSE
-       int rtnval;
+       int fd     = fileno(stream);
+       int rtnval = fclose(stream);
 
-       while ((rtnval = fclose(stream)) == EOF && (errno == EINTR)) ;
+       if (rtnval == EOF && (errno == EINTR))
+               while (((rtnval=close(fd))<0) && (errno == EINTR));
        return rtnval;
 #else
        return fclose(stream);