bug-bash
[Top][All Lists]
Advanced

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

Re: Severe memleak in sequence expressions?


From: Marc Schiffbauer
Subject: Re: Severe memleak in sequence expressions?
Date: Wed, 30 Nov 2011 23:34:04 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

* Greg Wooledge schrieb am 30.11.11 um 14:28 Uhr:
> On Wed, Nov 30, 2011 at 12:37:36AM +0100, Marc Schiffbauer wrote:
> > echo {0..10000000}>/dev/null
> > 
> > This makes my system starting to swap as bash will use several GiB of
> > memory.
> 
> Brace expansion is just a short way of typing a longer list of words.
> If you type {0..9} bash still has to expand it out to 0 1 2 3 4 5 6 7 8 9
> and then pass all of those words as arguments to echo.  (Granted, echo
> is a builtin, so there *could* be some sort of shortcut there....)
> 
> > If I choose a way bigger number bash "just" seems to crash:
> > 
> > mschiff@lisa ~ $ echo {1..1000000000000000000}>/dev/null
> > bash: xmalloc: cannot allocate 11892949016 bytes (135168 bytes allocated)
> > mschiff@lisa ~ $
> > 
> > Is this a bug?
> 
> In my opinion, no.  You're asking bash to generate a list of words from 0
> to 1000000000000000000 all at once.  It faithfully attempts to do so.

Yeah, ok but it will not free the mem it allocated later on (see
other mail)

> If you want to loop over integers, "for" is much better suited:
> 
> for ((i=1; i<=1000000000000000000; i++)); do
>   whatever
> done

ok, sure. I was just wondering if that massive amount of memory
is ok for that.

> 
> This will not require that all of the words from 1 to 1000000000000000000
> be generated in advance.  It will simply keep one word at a time in the
> loop variable.
> 
> (Bear in mind that bash can only handle 64-bit integer arithmetic; and
> bash 2.05 and earlier can only handle 32-bit integer arithmetic.)

will do, thx ;)

-Marc
-- 
8AAC 5F46 83B4 DB70 8317  3723 296C 6CCA 35A6 4134



reply via email to

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