Skip to content

Commit

Permalink
Merge pull request ValveSoftware#200 from kingtaurus/dev_alloc
Browse files Browse the repository at this point in the history
Fix for Issue ValveSoftware#199;
  • Loading branch information
Peter Lohrmann authored and Peter Lohrmann committed Apr 2, 2015
2 parents 549c60f + 94bbac8 commit 810c2de
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 810c2de

Please sign in to comment.