bug-tar
[Top][All Lists]
Advanced

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

[Bug-tar] Error "Cannot allocate memory" incorrectly reported in some ca


From: Frédéric Jolliton
Subject: [Bug-tar] Error "Cannot allocate memory" incorrectly reported in some cases.
Date: Sun, 23 Oct 2005 08:40:34 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Hi,

# uname -a
Linux tania 2.6.12.1-vs2.0-rc4 #1 Fri Jul 1 08:55:19 CEST 2005 i686 AMD 
Duron(tm) processor AuthenticAMD GNU/Linux
# ls|wc -l
35400
# tar c .
tar: .: Cannot savedir: Cannot allocate memory
tar: Error exit delayed from previous errors

Here is what cause this error, reported by ltrace -S:

mremap(0xb7d97000, 266240, 528384, MREMAP_MAYMOVE) = -1 ENOMEM (Cannot allocate 
memory)
mmap2(NULL, 528384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xb7d16000
munmap(0xb7d97000, 266240)              = 0

This is inside realloc(). When mremap fail, it set errno to ENOMEM,
but then mmap2 is performed instead and previous memory is unmap-ed.

While realloc succeed in this case, errno is set to ENOMEM !

This happen in savedir, when it call xrealloc.

It's why I think that lib/xmalloc.c/xnrealloc_inline() should save
errno before calling realloc, and its value if realloc succeed. Unless
it's more appropriate to do that in savedir directly.

I fixed it with:

-=-=-
--- tar-1.15.1.orig/lib/xmalloc.c       2004-12-17 17:11:32.000000000 +0100
+++ tar-1.15.1/lib/xmalloc.c    2005-10-23 08:37:18.000000000 +0200
@@ -25,6 +25,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #ifndef SIZE_MAX
 # define SIZE_MAX ((size_t) -1)
@@ -62,8 +63,10 @@
 static inline void *
 xnrealloc_inline (void *p, size_t n, size_t s)
 {
+  int save_errno = errno;
   if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0))
     xalloc_die ();
+  errno = save_errno;
   return p;
 }
-=-=-

-- 
Frédéric Jolliton




reply via email to

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