GNU bug report logs - #13530
head: memory exhausted when printing all from stdin but last P/E bytes

Previous Next

Package: coreutils;

Reported by: Lei Zhang <lei.zhang <at> uwaterloo.ca>

Date: Wed, 23 Jan 2013 02:43:01 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: Lei Zhang <lei.zhang <at> uwaterloo.ca>, 13530 <at> debbugs.gnu.org
Subject: bug#13530: head: memory exhausted when printing all from stdin but last P/E bytes
Date: Wed, 23 Jan 2013 13:53:47 +0100
On 01/23/2013 01:34 PM, Pádraig Brady wrote:
> There is the argument that we _should_ allocate
> everything up front to indicate immediately
> that the system can't (currently) support the requested operation,
> but given the 'currently' caveat above I guess it's
> more general to fail when we actually run out of mem?

head doesn't "allocate everything up front" - instead, it only
allocates the pointer array which would hold the actual data.
The strategy in elide_tail_lines_pipe() seems more robust:
it allocates memory when needed.

Or another (probably martian) idea:
what about a tmpfile()?

>       free_mem:
> -      for (i = 0; i < n_bufs; i++)
> +      for (i = 0; i < n_alloc; i++)
>           free (b[i]);
>         free (b);

BTW: both in the old and the new version, the loop can break
if (b[i] == 0) because the array is filled from the beginning.

-      for (i = 0; i < n_bufs; i++)
+      for (i = 0; i < n_bufs && b[i]; i++)

This makes "echo 123 | head -c -T" ~40% faster here on my PC.

Have a nice day,
Berny






This bug report was last modified 12 years and 42 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.