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