From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: copy-file fd leak Date: Wed, 28 Jul 2004 08:57:19 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <871xix2h4g.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1090969097 1023 80.91.224.253 (27 Jul 2004 22:58:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 27 Jul 2004 22:58:17 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Jul 28 00:58:05 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BpatZ-0007ua-00 for ; Wed, 28 Jul 2004 00:58:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bpawf-0000jw-Q2 for guile-devel@m.gmane.org; Tue, 27 Jul 2004 19:01:17 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BpawI-0000hv-6y for guile-devel@gnu.org; Tue, 27 Jul 2004 19:00:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BpawG-0000gu-PT for guile-devel@gnu.org; Tue, 27 Jul 2004 19:00:53 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BpawG-0000gh-I7 for guile-devel@gnu.org; Tue, 27 Jul 2004 19:00:52 -0400 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Bpat3-0006rd-Gx for guile-devel@gnu.org; Tue, 27 Jul 2004 18:57:34 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i6RMvUje021960 for ; Wed, 28 Jul 2004 08:57:30 +1000 Original-Received: from localhost (ppp20F1.dyn.pacific.net.au [61.8.32.241]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i6RMvTgH030811 for ; Wed, 28 Jul 2004 08:57:30 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1Bpasr-0000xF-00; Wed, 28 Jul 2004 08:57:21 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3897 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3897 --=-=-= * filesys.c (scm_copy_file): Avoid fd leak when destination file cannot be opened. (This is for 1.6 too.) --=-=-= Content-Disposition: attachment; filename=filesys.c.fd-leak.diff --- filesys.c.~1.127.~ 2004-07-24 09:08:47.000000000 +1000 +++ filesys.c 2004-07-24 18:55:19.000000000 +1000 @@ -1424,7 +1424,10 @@ newfd = open (SCM_STRING_CHARS (newfile), O_WRONLY | O_CREAT | O_TRUNC, oldstat.st_mode & 07777); if (newfd == -1) - SCM_SYSERROR; + { + close (oldfd); + SCM_SYSERROR; + } while ((n = read (oldfd, buf, sizeof buf)) > 0) if (write (newfd, buf, n) != n) --=-=-= Content-Disposition: attachment; filename=filesys.test ;;;; filesys.test --- test file system functions -*- scheme -*- ;;;; ;;;; Copyright (C) 2004 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 2.1 of the License, or (at your option) any later version. ;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;;; Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (define-module (test-suite test-filesys) #:use-module (test-suite lib)) ;;; ;;; copy-file ;;; (with-test-prefix "copy-file" ;; return next prospective file descriptor number (define (next-fd) (let ((fd (dup 0))) (close fd) fd)) ;; in guile 1.6.4 and earlier, copy-file didn't close the input fd when ;; the output could not be opened (pass-if "fd leak when dest unwritable" (let ((old-next (next-fd))) (false-if-exception (copy-file "/dev/null" "no/such/dir/foo")) (= old-next (next-fd))))) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel --=-=-=--