bug-gnulib
[Top][All Lists]
Advanced

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

Re: [Bug-tar] Error "Cannot allocate memory" incorrectly reported in som


From: Sergey Poznyakoff
Subject: Re: [Bug-tar] Error "Cannot allocate memory" incorrectly reported in some cases.
Date: Fri, 28 Oct 2005 15:41:01 EEST

Frédéric Jolliton <address@hidden> wrote:

> 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'd rather say it's the responsibility of savedir() itself. The usual
convention for any function is to not bother about the errno value if
it finishes successfully. I don't see any reason for xmalloc() to be
an exception. So, I propose the following patch:

Index: lib/savedir.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/savedir.c,v
retrieving revision 1.26
diff -p -u -r1.26 savedir.c
--- lib/savedir.c       19 Sep 2005 17:28:15 -0000      1.26
+++ lib/savedir.c       28 Oct 2005 12:39:06 -0000
@@ -104,6 +104,7 @@ savedir (const char *dir)
              while (allocated <= used + entry_size);
 
              name_space = xrealloc (name_space, allocated);
+              errno = 0;
            }
          memcpy (name_space + used, entry, entry_size);
          used += entry_size;


Regards,
Sergey




reply via email to

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