changeset 12461:673d93dccba1

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 <solar@openwall.com>. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Sat, 19 Dec 2009 09:28:36 -0700
parents 282eecca2301
children f7383de75775
files ChangeLog lib/canonicalize.c
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-19  Eric Blake  <ebb9@byu.net>
+
+	canonicalize: reduce memory usage
+	* lib/canonicalize.c (canonicalize_filename_mode): Trim the
+	allocation to size.
+	Reported by Solar Designer <solar@openwall.com>.
+
 2009-12-19  Bruno Haible  <bruno@clisp.org>
 
 	New module attribute 'Applicability'.
--- 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)