This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug malloc/22611] New: malloc might succeed and set errno to ENOMEM in case of heap allocation failure
- From: "aurelien at aurel32 dot net" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Thu, 14 Dec 2017 22:20:23 +0000
- Subject: [Bug malloc/22611] New: malloc might succeed and set errno to ENOMEM in case of heap allocation failure
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=22611
Bug ID: 22611
Summary: malloc might succeed and set errno to ENOMEM in case
of heap allocation failure
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: malloc
Assignee: unassigned at sourceware dot org
Reporter: aurelien at aurel32 dot net
Target Milestone: ---
tst-realloc tests, among others things that malloc and friends to not set errno
to ENOMEM in case of successful memory allocation. This test always fail on
sparc64 with "Error: errno is set but should not be".
On sparc64 it happens that, for a reason I don't really understand, when
running processes by explicitly calling ld.so, all the heap allocation fail, ie
the call to brk return an unchanged address. sysmalloc first call sbrk through
the call to MORECORE (size). This sets errno to ENOMEM. Then mmap is used as a
fallback and succeed, but doesn't reset errno to its initial value.
While the way to trigger the issue within the testsuite is sparc64 specific,
the issue itself is architecture independent and can easily be reproduced for
example on x86-64 by playing with ulimit:
$ cat > test.c << EOF
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main()
{
errno = 0;
void *data = malloc(32*1024*1024);
int saved_errno = errno;
printf("errno = %i\n", saved_errno);
}
EOF
$ gcc test.c
$ ./a.out
errno = 0
$ (ulimit -d 1024 ; ./a.out)
errno = 12
--
You are receiving this mail because:
You are on the CC list for the bug.