bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH,HURD] Fix mknod cleanup on error


From: Samuel Thibault
Subject: [PATCH,HURD] Fix mknod cleanup on error
Date: Sat, 12 Nov 2011 02:29:27 +0100
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

Hello,

mknod() spuriously deallocates its node port on errors such as EROFS.

Samuel

2011-11-11  Samuel Thibault  <address@hidden>

* sysdeps/mach/hurd/xmknodat.c (__xmknodat): Also store result of `__dir_mkfile'
in new `errnode' variable. Only deallocate `node' if errnode is 0.

diff --git a/sysdeps/mach/hurd/xmknodat.c b/sysdeps/mach/hurd/xmknodat.c
index b222759..98ab4f4 100644
--- a/sysdeps/mach/hurd/xmknodat.c
+++ b/sysdeps/mach/hurd/xmknodat.c
@@ -1,5 +1,5 @@
 /* Create a device file relative to an open directory.  Hurd version.
-   Copyright (C) 1991,1992,1993,1994,1995,1996,1999,2002,2005,2006
+   Copyright (C) 1991,1992,1993,1994,1995,1996,1999,2002,2005,2006,2011
        Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -35,7 +35,7 @@
 int
 __xmknodat (int vers, int fd, const char *path, mode_t mode, dev_t *dev)
 {
-  error_t err;
+  error_t errnode, err;
   file_t dir, node;
   char *name;
   char buf[100], *bp;
@@ -95,7 +95,7 @@ __xmknodat (int vers, int fd, const char *path, mode_t mode, 
dev_t *dev)
     return -1;
 
   /* Create a new, unlinked node in the target directory.  */
-  err = __dir_mkfile (dir, O_WRITE, (mode & ~S_IFMT) & ~_hurd_umask, &node);
+  errnode = err = __dir_mkfile (dir, O_WRITE, (mode & ~S_IFMT) & ~_hurd_umask, 
&node);
 
   if (! err && translator != NULL)
     /* Set the node's translator to make it a device.  */
@@ -110,7 +110,8 @@ __xmknodat (int vers, int fd, const char *path, mode_t 
mode, dev_t *dev)
     err = __dir_link (dir, node, name, 1);
 
   __mach_port_deallocate (__mach_task_self (), dir);
-  __mach_port_deallocate (__mach_task_self (), node);
+  if (! errnode)
+    __mach_port_deallocate (__mach_task_self (), node);
 
   if (err)
     return __hurd_fail (err);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]