bug-gnulib
[Top][All Lists]
Advanced

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

Re: [bug-gnulib] xreadlink.c initial buffer size guesstimate


From: Bruno Haible
Subject: Re: [bug-gnulib] xreadlink.c initial buffer size guesstimate
Date: Fri, 12 Jan 2007 17:24:04 +0100
User-agent: KMail/1.9.1

Liyang HU wrote:
> I've been getting ``ls: memory exhausted'' messages, which I eventually
> tracked down to xreadlink() attempting to allocate several hundred MB of
> memory, since that's what lstat() returns[0] for the symlink's st_size.
> In actuality, the length of the symlink were mostly under 128 bytes.

The xreadlink.c in GNU gettext (also originally from Jim Meyering)
  
http://cvs.savannah.gnu.org/viewcvs/*checkout*/gettext/gnulib-local/lib/xreadlink.c?rev=1.3&root=gettext

should be more robust: It uses an initial buffer size of 1024, and
requires more only if readlink() reports that the link is longer. As such,
it doesn't require an st_size guess or estimate.

And in the frequent case that the link is smaller than 1024 and that the
guess was right, both implementations call xmalloc just once.

Bruno




reply via email to

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