From 5e6798cb4d3923bf1768d2a1d269d0932f8fc7e2 Mon Sep 17 00:00:00 2001 From: Brian Barrett Date: Thu, 19 Jan 2006 18:48:58 +0000 Subject: [PATCH] * with ptmalloc2, prefer syscall over dlsym for calling the real munmap. This makes illegal free() calls behave in a much more rational way. You'll still probably die, but your stack trace will not have 3 billion pages of recusion inside the memory allocator. * Fix illegal free in the opal_wrapper code. basename() returns a string in a static buffer, so it shouldn't be free()ed. It also shouldn't be left around so long, as another call to basename() may whack the returned buffer. So leave the free and add a strdup() around the basename() call. * Turn off some unneeded debugging in the opal_wrapper code that would list the comamnd to be run, regardless of the -showme option. This commit was SVN r8758. --- opal/mca/memory/ptmalloc2/opal_ptmalloc2_munmap.c | 14 +++++++------- opal/tools/wrappers/opal_wrapper.c | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/opal/mca/memory/ptmalloc2/opal_ptmalloc2_munmap.c b/opal/mca/memory/ptmalloc2/opal_ptmalloc2_munmap.c index 0cf1de7b3a..27dd75e179 100644 --- a/opal/mca/memory/ptmalloc2/opal_ptmalloc2_munmap.c +++ b/opal/mca/memory/ptmalloc2/opal_ptmalloc2_munmap.c @@ -22,15 +22,15 @@ #include #include #if defined(HAVE___MUNMAP) -/* here so we only include dlfcn if we absolutely have to */ +/* here so we only include others if we absolutely have to */ +#elif defined(HAVE_SYSCALL) +#include +#include #elif defined(HAVE_DLSYM) #ifndef __USE_GNU #define __USE_GNU #endif #include -#elif defined(HAVE_SYSCALL) -#include -#include #endif #include "opal/memoryhooks/memory_internal.h" @@ -59,7 +59,7 @@ munmap(void* addr, size_t len) int opal_mem_free_ptmalloc2_munmap(void *start, size_t length, int from_alloc) { -#if !defined(HAVE___MUNMAP) && defined(HAVE_DLSYM) +#if !defined(HAVE___MUNMAP) && !defined(HAVE_SYSCALL) && defined(HAVE_DLSYM) static int (*realmunmap)(void*, size_t); #endif @@ -67,6 +67,8 @@ opal_mem_free_ptmalloc2_munmap(void *start, size_t length, int from_alloc) #if defined(HAVE___MUNMAP) return __munmap(start, length); +#elif defined(HAVE_SYSCALL) + return syscall(__NR_munmap, start, length); #elif defined(HAVE_DLSYM) if (NULL == realmunmap) { union { @@ -79,8 +81,6 @@ opal_mem_free_ptmalloc2_munmap(void *start, size_t length, int from_alloc) } return realmunmap(start, length); -#elif defined(HAVE_SYSCALL) - return syscall(__NR_munmap, start, length); #else #error "Can not determine how to call munmap" #endif diff --git a/opal/tools/wrappers/opal_wrapper.c b/opal/tools/wrappers/opal_wrapper.c index f0e3eb0f52..eb9d3e116c 100644 --- a/opal/tools/wrappers/opal_wrapper.c +++ b/opal/tools/wrappers/opal_wrapper.c @@ -272,7 +272,7 @@ main(int argc, char *argv[]) int exit_status = 0, ret, flags = 0, i; int exec_argc = 0, user_argc = 0; char **exec_argv = NULL, **user_argv = NULL; - char *exec_command, *base_argv0; + char *exec_command, *base_argv0 = NULL; bool disable_flags = true; bool real_flag = false; @@ -287,7 +287,7 @@ main(int argc, char *argv[]) * ****************************************************/ - base_argv0 = basename(argv[0]); + base_argv0 = strdup(basename(argv[0])); if (OPAL_SUCCESS != (ret = data_init(base_argv0))) { return ret; } @@ -511,7 +511,7 @@ main(int argc, char *argv[]) } else { char *tmp; -#if 1 +#if 0 exec_command = opal_argv_join(exec_argv, ' '); printf("command: %s\n", exec_command); #endif