bug-gnulib
[Top][All Lists]
Advanced

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

Re: malloc failing with EAGAIN


From: Bruno Haible
Subject: Re: malloc failing with EAGAIN
Date: Sun, 01 May 2022 22:28:45 +0200

Paul Eggert wrote:
> malloc can fail with EAGAIN 
> on GNU/Linux and I assume other errno values are also possible.

Indeed [1], although the glibc manual [2] and the Linux man page [3]
don't mention it.

The meaning of EAGAIN in this case is as documented for the mmap()
system call [4]:
  "too much memory has been locked"

The usual meaning of EAGAIN [5] does not apply here:
  - Stating in an error message that "Resource temporarily unavailable"
    is bad, because the error does not come from outside the process, it
    originates in the process itself.
  - Similarly, trying again later (e.g. in a loop) will not help, since
    the situation originates in the process itself.

So, IMO, applications should
  - better print "Out of memory" or "Cannot allocate memory", rather than
    "Resource temporarily unavailable".
  - just fail, never retry.

I would argue that glibc should use a different errno value in this case.
What do you think?

Bruno

[1] https://stackoverflow.com/questions/34165276/malloc-setting-errno-to-eagain
[2] https://www.gnu.org/software/libc/manual/html_mono/libc.html
[3] https://www.kernel.org/doc/man-pages/online/pages/man3/malloc.3.html
[4] https://www.kernel.org/doc/man-pages/online/pages/man2/mmap.2.html
[5] https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html






reply via email to

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