Description of problem:
On [Linux 2.4.20-2.48bigmem #1 SMP Thu Feb 13 11:31:10 EST 2003 i686
i686 i386 GNU/Linux] in a threaded application, when calling malloc, sometimes
errno is set to EINVAL. The malloc function does seem to return a valid
pointer, as apposed to NULL which is supposed to be returned on an actual error.
According to the man page, error codes of only 0 or ENOMEM are expected. The
man pages on other platforms suggest that EINVAL may be set if malloc(0) is
called. We are not calling malloc with an argument of 0.
Version-Release number of selected component (if applicable):
gcc version 3.2.1 20030202 (Red Hat Linux 8.0 3.2.1-7)
Setting the environment variable MALLOC_CHECK_ = 1 or 2 eliminates this
problem. I don't know why, as MALLOC_CHECK_ is only supposed to be a debugging
aid and is not supposed to effect the behavior of the actual malloc function
call. However, obviously it does, as malloc is no longer setting errno to
You mean that malloc returns non-NULL and sets errno to EINVAL?
That is completely legal. With the exception of a few routines named in the
standards (I remember ATM only some math functions, there are a few others
I think), errno has defined value only after function fails (typically
returns -1, in the case of malloc NULL).
So, unless malloc returns NULL, you shouldn't look what value errno has,
it can have any.