[PATCH:libXpm] Close fd if fdopen() or xpmPipeThrough() fails in OpenWriteFile()

Alan Coopersmith alan.coopersmith at oracle.com
Mon Apr 22 13:25:57 PDT 2013


Fixes leak found by parfait 1.1 bug checking tool:
   File Descriptor Leak: Leaked File Descriptor fd
        at line 350 of lib/libXpm/src/WrFFrI.c in function 'OpenWriteFile'.
          fd initialized at line 332 with open
          fd leaks when strcmp(".Z", (filename + (len - 2))) != 0 at line 337
              and strcmp(".gz", (filename + (len - 3))) != 0 at line 340.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/WrFFrI.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/WrFFrI.c b/src/WrFFrI.c
index b592fa1..d074516 100644
--- a/src/WrFFrI.c
+++ b/src/WrFFrI.c
@@ -346,8 +346,10 @@ OpenWriteFile(
 	    mdata->stream.file = fdopen(fd, "w");
 	    mdata->type = XPMFILE;
 	}
-	if (!mdata->stream.file)
+	if (!mdata->stream.file) {
+	    close(fd);
 	    return (XpmOpenFailed);
+	}
     }
     return (XpmSuccess);
 }
-- 
1.7.9.2



More information about the xorg-devel mailing list