From ed518e4b22bdb33da122a7a394f831693ec65840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 24 Feb 2007 15:26:02 +0000 Subject: [PATCH] Fixed "cp" (and "mv") leaking file descriptors like crazy when copying attributes, thanks to Ingo for noticing this. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20223 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/coreutils/src/copy.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bin/coreutils/src/copy.c b/src/bin/coreutils/src/copy.c index 809a7e4899..db46ce397d 100644 --- a/src/bin/coreutils/src/copy.c +++ b/src/bin/coreutils/src/copy.c @@ -163,8 +163,8 @@ copy_attributes(int fromFd, int toFd) static int copy_attributes_by_name(const char *from, const char *to, int resolveLinks) { - int fromFd, toFd; - printf("%s -> %s\n", from, to); + int fromFd, toFd, result; + fromFd = open(from, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE)); if (fromFd < 0) return -1; @@ -175,7 +175,12 @@ copy_attributes_by_name(const char *from, const char *to, int resolveLinks) return -1; } - return copy_attributes(fromFd, toFd); + result = copy_attributes(fromFd, toFd); + + close(fromFd); + close(toFd); + + return result; }