# HG changeset patch # User Eric Blake # Date 1261240116 25200 # Node ID 673d93dccba160accdbf2470222df9f89e41b22c # Parent 282eecca2301db05cf652d4f6b9b8e3c591c7a3e canonicalize: reduce memory usage canonicalize was returning a 4k buffer for everything, even though the majority of canonical path names are much shorter. This resulted in a lot of unused memory, which in turn made tar run out of memory when tracking a lot of files: http://lists.gnu.org/archive/html/bug-tar/2009-12/msg00011.html * lib/canonicalize.c (canonicalize_filename_mode): Trim the allocation to size. Reported by Solar Designer . Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-12-19 Eric Blake + + canonicalize: reduce memory usage + * lib/canonicalize.c (canonicalize_filename_mode): Trim the + allocation to size. + Reported by Solar Designer . + 2009-12-19 Bruno Haible New module attribute 'Applicability'. diff --git a/lib/canonicalize.c b/lib/canonicalize.c --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -272,6 +272,8 @@ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && *dest == '/') dest++; *dest = '\0'; + if (rname_limit != dest + 1) + rname = xrealloc (rname, dest - rname + 1); free (extra_buf); if (ht)