PR217695 malloc/calloc/realloc/memalign failure doesn't set errno to ENOMEM
commit1c9a0bf58a47e855e6e5bf78a30bcee0af835804
authorMark Wielaard <mark@klomp.org>
Fri, 12 Feb 2021 22:29:34 +0000 (12 23:29 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 17 Feb 2021 12:14:41 +0000 (17 13:14 +0100)
treef92f8479a92f417e9e6c6eb9b9a55d251ae8f301
parentee01ed8f13d235ad84cdca11ca88523cc5b52287
PR217695 malloc/calloc/realloc/memalign failure doesn't set errno to ENOMEM

When one of the allocation functions in vg_replace_malloc failed
they return NULL, but didn't set errno. This is slightly tricky since
errno is implementation defined and might be a macro. In the case of
glibc ernno is defined as:

  extern int *__errno_location (void) __THROW __attribute__ ((__const__));
  #define errno (*__errno_location ())

We can use the same trick as we use for __libc_freeres in
coregrind/vg_preloaded.c. Define the function as "weak". This means
it will only be defined if another library (glibc in this case)
actually provides a definition. Otherwise it will be NULL.
So we will only call it if it is defined and one of the allocation
functions failed, returned NULL.

Include a new linux only memcheck testcase, enomem.vgtest.

https://bugs.kde.org/show_bug.cgi?id=217695
NEWS
coregrind/m_replacemalloc/vg_replace_malloc.c
memcheck/tests/linux/Makefile.am
memcheck/tests/linux/enomem.c [new file with mode: 0644]
memcheck/tests/linux/enomem.stderr.exp [new file with mode: 0644]
memcheck/tests/linux/enomem.stdout.exp [new file with mode: 0644]
memcheck/tests/linux/enomem.vgtest [new file with mode: 0644]