canonicalize: reduce memory usage
authorEric Blake <ebb9@byu.net>
Sat, 19 Dec 2009 16:28:36 +0000 (09:28 -0700)
committerEric Blake <ebb9@byu.net>
Sat, 19 Dec 2009 18:53:38 +0000 (11:53 -0700)
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>
ChangeLog
lib/canonicalize.c

index d0673a93c35b6e1ea52bea68682a8f747373badf..4e3a924c1e74029ae52b5519861fda4919eb0151 100644 (file)
--- 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'.
index 2f008e0689a369f1486113704765ce1fc18a4707..612a0d0fec007a291dccb8c6238ec15333de576b 100644 (file)
@@ -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)