From 31b08222e46a5c824d06574863b8f73c72aea677 Mon Sep 17 00:00:00 2001 From: pascal Date: Tue, 20 Oct 2015 11:15:07 +0000 Subject: [PATCH] On xmalloc failure, stop trying to determine the total amount of allocated memory up to this point by using sbrk(2). This is of course wildly incorrect for any mmap-based malloc(3). This also makes it possible to bring pledge(2) to gnu/. comments kettenis@, ok miod@ --- gnu/lib/libiberty/src/xmalloc.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/gnu/lib/libiberty/src/xmalloc.c b/gnu/lib/libiberty/src/xmalloc.c index 3e97aab563f..5c95b8b0dd9 100644 --- a/gnu/lib/libiberty/src/xmalloc.c +++ b/gnu/lib/libiberty/src/xmalloc.c @@ -96,44 +96,19 @@ void *sbrk (ptrdiff_t); /* The program name if set. */ static const char *name = ""; -#ifdef HAVE_SBRK -/* The initial sbrk, set when the program name is set. Not used for win32 - ports other than cygwin32. */ -static char *first_break = NULL; -#endif /* HAVE_SBRK */ - void xmalloc_set_program_name (const char *s) { name = s; -#ifdef HAVE_SBRK - /* Win32 ports other than cygwin32 don't have brk() */ - if (first_break == NULL) - first_break = (char *) sbrk (0); -#endif /* HAVE_SBRK */ } void xmalloc_failed (size_t size) { -#ifdef HAVE_SBRK - extern char **environ; - size_t allocated; - - if (first_break != NULL) - allocated = (char *) sbrk (0) - first_break; - else - allocated = (char *) sbrk (0) - (char *) &environ; - fprintf (stderr, - "\n%s%sout of memory allocating %lu bytes after a total of %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) size, (unsigned long) allocated); -#else /* HAVE_SBRK */ fprintf (stderr, "\n%s%sout of memory allocating %lu bytes\n", name, *name ? ": " : "", (unsigned long) size); -#endif /* HAVE_SBRK */ xexit (1); } -- 2.20.1