bug-patch
[Top][All Lists]
Advanced

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

[bug-patch] [PATCH] patch: don't close a negative file descriptor


From: Jim Meyering
Subject: [bug-patch] [PATCH] patch: don't close a negative file descriptor
Date: Wed, 01 Aug 2012 15:32:56 +0200

I ran a valgrind-wrapped patch through the test suite,
and saw many of these warnings:

    ==10347== Warning: invalid file descriptor -1 in syscall close()
    ==10347==    at 0x31686E4B80: __close_nocancel (in /usr/lib64/libc-2.15.so)
    ==10347==    by 0x4054BA: re_input (inp.c:64)
    ==10347==    by 0x404353: main (patch.c:639)

This suggests that the above is triggered by many of the test cases:

    $ grep -h Command..patch $(grep -l Warn *)
    ==10347== Command: patch -f -p1
    ==10472== Command: patch -p1
    ==10561== Command: patch -f -n
    ==10578== Command: patch -f -p0 --dry-run
    ==10739== Command: patch -p0 --read-only=fail
    ==10905== Command: patch
    ==10947== Command: patch -f -p0 --dry-run
    ==11018== Command: patch
    ==11054== Command: patch -p0
    ==11199== Command: patch -f -p1 --dry-run
    ==11229== Command: patch
    ==11332== Command: patch -f -p0 --dry-run
    ==11391== Command: patch -f -e
    ==11460== Command: patch -f -p0 --dry-run
    ==11491== Command: patch f
    ==11721== Command: patch -f -p0
    ==11729== Command: patch c

This patch fixes it:

>From 94aaeff8afa7e1cf1c5107470644f8b374d9cc00 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 1 Aug 2012 15:32:27 +0200
Subject: [PATCH] patch: don't close a negative file descriptor

* src/inp.c (re_input): Don't close FD if it's negative.
---
 src/inp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/inp.c b/src/inp.c
index 9cc140f..6387587 100644
--- a/src/inp.c
+++ b/src/inp.c
@@ -61,7 +61,8 @@ re_input (void)
        }
     }
     else {
-       close (tifd);
+       if (tifd >= 0)
+         close (tifd);
        tifd = -1;
        if (tibuf[0])
          {
--
1.7.12.rc1.10.g97c7934



reply via email to

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