bug-grep
[Top][All Lists]
Advanced

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

Re: [bug #31928] grep should exit(2) when memory is exhausted


From: Paolo Bonzini
Subject: Re: [bug #31928] grep should exit(2) when memory is exhausted
Date: Mon, 20 Dec 2010 16:12:11 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101103 Fedora/1.0-0.33.b2pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.6

> When grep exhausts memory due to trying to read()
> or mmap() a large binary file, it prints
> 
>    grep: memory exhausted
> 
> on stderr, then exits with exit status, 1.
> 
> I expect the failure, but I believe that
> it should exit(2), or something greater than 1,
> in order to distinguish this type of failure
> from simply a failure to find a match.

Thanks, this should be enough to fix it:

diff --git a/src/main.c b/src/main.c
index b7d1c78..500c473 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1773,6 +1773,7 @@ main (int argc, char **argv)
   int default_context;
   FILE *fp;
 
+  exit_failure = EXIT_TROUBLE;
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
   program_name = argv[0];
diff --git a/NEWS b/NEWS
index 539e978..bd75640 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ GNU grep NEWS                                    -*- outline -*-
   support was introduced in 2.5.2, though the steps needed to reproduce
   it changed in grep-2.6]
 
+  grep erroneously returned with exit status 1 on some memory allocation 
+  failure. [bug present since "the beginning"]
+
 * Noteworthy changes in release 2.7 (2010-09-16) [stable]
 
 ** Bug fixes


The bug is present since grep started using xmalloc

commit 832757b094adc56acf2dd728de1f2459228d1fdf
Author: Alain Magloire <address@hidden>
Date:   Sun Mar 4 05:33:12 2001 +0000

    from GNU tar and fetish.

which is why I'm marking it as "present since the beginning" in NEWS.

Paolo



reply via email to

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