bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] Re: tar 1.22.90 memory usage


From: Sergey Poznyakoff
Subject: [Bug-tar] Re: tar 1.22.90 memory usage
Date: Thu, 17 Dec 2009 10:46:14 +0200

Solar Designer <address@hidden> ha escrit:

> It turns out that canonicalize_filename_mode(), which is used by the
> "new functions" mentioned above, allocates memory for at least
> PATH_MAX bytes

Thanks for reporting.  I overlooked that.  I have forwarded your patch
to bug-gnulib mailing list (that function is part of gnulib, not the
tar proper).  In the meantime, I am going to install the attached 
change.

> Besides fixing canonicalize_filename_mode() or its uses, maybe "struct
> directory" could be made more compact again?  For example, maybe "name"
> could be allocated along with the struct like it was before instead of
> being referenced through a pointer?

Perhaps this would save a couple of bytes, but I'm afraid it will make
the code less manageable.

> Maybe "caname" could be allocated along with the struct too?  The
> pointer field would have to remain, but at least we'd save on malloc
> overhead (we will have fewer allocations).

Caname is allocated using normalize_filename, so packing it into the
structure won't diminish the number of allocations.  Besides,
it would mean one more call to free, which will add its overhead.

Nevertheless, thanks for the suggestions, I will try to diminish
the memory consumption anyway.

Actually, I wonder whether it would not be better to keep the
directory status information in some kind of external cache (e.g.
in a DBM file).  It would certainly solve the memory consumption
problem, at the expense of slightly longer execution time and an extra
software dependency.  What do you think?

Regards,
Sergey

diff --git a/src/misc.c b/src/misc.c
index cdb2608..f52aaff 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -233,7 +233,8 @@ zap_slashes (char *name)
 char *
 normalize_filename (const char *name)
 {
-  return zap_slashes (canonicalize_filename_mode (name, CAN_MISSING));
+  char *p = zap_slashes (canonicalize_filename_mode (name, CAN_MISSING));
+  return realloc (p, strlen (p) + 1);
 }
 
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]