From 94bbac81a50de12271d3e573fcfce9c10196ae5c Mon Sep 17 00:00:00 2001 From: Gregory King Date: Wed, 1 Apr 2015 10:21:27 -0700 Subject: [PATCH] Fix for Issue #199; alloc.c if it was being used for libbacktrace was missing the definition for backtrace_strdup. Changes: ======= src/libbacktrace/CMakeLists.txt (1) quotes around the header (matching the cmake documentation for use the function); src/libbacktrace/alloc.c: (1) added #include [required for the use of memcpy] (2) backtrace_strdup definition [copied from mmap.c] --- src/libbacktrace/CMakeLists.txt | 2 +- src/libbacktrace/alloc.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/libbacktrace/CMakeLists.txt b/src/libbacktrace/CMakeLists.txt index 2f5d29c7..233d12ae 100644 --- a/src/libbacktrace/CMakeLists.txt +++ b/src/libbacktrace/CMakeLists.txt @@ -116,7 +116,7 @@ else () set (BACKTRACE_SUPPORTED 0) endif () -check_symbol_exists (mmap sys/mman.h HAVE_MMAP) +check_symbol_exists (mmap "sys/mman.h" HAVE_MMAP) if (HAVE_MMAP) set (VIEW_FILE mmapio.c) diff --git a/src/libbacktrace/alloc.c b/src/libbacktrace/alloc.c index 37eca653..81be2829 100644 --- a/src/libbacktrace/alloc.c +++ b/src/libbacktrace/alloc.c @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include +#include #include #include @@ -59,7 +60,34 @@ backtrace_alloc (struct backtrace_state *state ATTRIBUTE_UNUSED, return ret; } -/* Free memory. */ +/* Allocate memory like strdup. */ + +char * +backtrace_strdup (struct backtrace_state *state, const char *str, + backtrace_error_callback error_callback, + void *data) +{ + char *ret; + + ret = NULL; + + if (str) + { + size_t size; + void *mem; + + size = strlen(str) + 1; + mem = backtrace_alloc (state, size, error_callback, data); + if (mem) + { + memcpy(mem, str, size); + ret = (char *)mem; + } + } + return ret; +} + +/* Free memory allocated by backtrace_alloc. */ void backtrace_free (struct backtrace_state *state ATTRIBUTE_UNUSED,