open: close the file descriptor if the file fails to open
authorH. Peter Anvin <hpa@zytor.com>
Fri, 20 Nov 2009 01:17:36 +0000 (17:17 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 20 Nov 2009 01:17:36 +0000 (17:17 -0800)
Close the file descriptor (freeing the file structure) when opening a
file fails.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/lib/sys/open.c

index aabbec2..aac5e6f 100644 (file)
@@ -72,13 +72,14 @@ int open(const char *pathname, int flags, ...)
     __com32.cs_intcall(0x22, &regs, &regs);
 
     if ((regs.eflags.l & EFLAGS_CF) || regs.esi.w[0] == 0) {
+       close(fd);
        errno = ENOENT;
        return -1;
     }
 
     {
        uint16_t blklg2;
-asm("bsrw %1,%0": "=r"(blklg2):"rm"(regs.ecx.w[0]));
+       asm("bsrw %1,%0" :  "=r" (blklg2) : "rm" (regs.ecx.w[0]));
        fp->i.blocklg2 = blklg2;
     }
     fp->i.length = regs.eax.l;