From: Eric Blake Date: Sat, 19 Dec 2009 16:28:36 +0000 (-0700) Subject: canonicalize: reduce memory usage X-Git-Tag: v0.1~5026 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=f65232a174c15c6c10273185f11b190cae5736ad;p=gnulib.git 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 index d0673a93c..4e3a924c1 100644 --- 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 index 2f008e068..612a0d0fe 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -272,6 +272,8 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) 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)