Skip to content

Commit

Permalink
Fix for Issue ValveSoftware#199;
Browse files Browse the repository at this point in the history
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 <string.h> [required for the use of memcpy]
  (2) backtrace_strdup definition [copied from mmap.c]
  • Loading branch information
kingtaurus committed Apr 1, 2015
1 parent 549c60f commit 94bbac8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libbacktrace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion src/libbacktrace/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. */
#include "config.h"

#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>

Expand All @@ -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,
Expand Down

0 comments on commit 94bbac8

Please sign in to comment.