Bug 86420 - malloc on bigmem SMP kernel returns EINVAL
Summary: malloc on bigmem SMP kernel returns EINVAL
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 9
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-03-21 19:05 UTC by Bob Nataly
Modified: 2007-04-18 16:52 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2004-10-03 19:56:00 UTC
Embargoed:


Attachments (Terms of Use)

Description Bob Nataly 2003-03-21 19:05:56 UTC
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)

Comment 1 Bob Nataly 2003-03-21 21:00:29 UTC
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 
EINVAL.


Comment 2 Jakub Jelinek 2003-03-21 21:07:57 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.