copyReg(): open out_fd with O_RDWR, fixed resource leak in error-case
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 1 Feb 2005 02:06:06 +0000 (02:06 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 1 Feb 2005 02:06:06 +0000 (02:06 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1838 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib_internal/unify-copy.c

index c67b48e..554c077 100644 (file)
@@ -63,7 +63,7 @@ copyReg(char const *src, struct stat const *src_stat,
        char const *dst)
 {
   int          in_fd  = open(src, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_LARGEFILE);
-  int          out_fd = in_fd==-1 ? -1 : open(dst, O_CREAT|O_EXCL, 0200);
+  int          out_fd = in_fd==-1 ? -1 : open(dst, O_RDWR|O_CREAT|O_EXCL, 0200);
   bool         res    = false;
   
   if (in_fd==-1 || out_fd==-1 ||
@@ -74,7 +74,7 @@ copyReg(char const *src, struct stat const *src_stat,
     ssize_t    l = read(in_fd, buf, sizeof buf);
     if (l==-1) goto err;
     if (l==0)  break;
-    if (!WwriteAll(out_fd, buf, l, 0)) return false;
+    if (!WwriteAll(out_fd, buf, l, 0)) goto err;
   }
 
   res = true;