diff options
author | John Reiser <jreiser@bitwagon.com> | 2011-03-21 15:04:40 -0400 |
---|---|---|
committer | William Cohen <wcohen@redhat.com> | 2011-03-21 15:04:40 -0400 |
commit | d206de4f3b62a74500e923d9090b07577007845a (patch) | |
tree | f4ea732d6b494caf06b0f640d1800d2c8bc428dc | |
parent | d0714687a3ae74a6320e036999d1ad70d7633eee (diff) | |
download | memstomp-d206de4f3b62a74500e923d9090b07577007845a.tar.gz memstomp-d206de4f3b62a74500e923d9090b07577007845a.tar.xz memstomp-d206de4f3b62a74500e923d9090b07577007845a.zip |
Prefer alloca() over malloc() where possible and small size
-rw-r--r-- | backtrace-symbols.c | 6 | ||||
-rw-r--r-- | memstomp.c | 6 |
2 files changed, 3 insertions, 9 deletions
diff --git a/backtrace-symbols.c b/backtrace-symbols.c index a8af6e4..aed39d6 100644 --- a/backtrace-symbols.c +++ b/backtrace-symbols.c @@ -45,6 +45,7 @@ #define false 0 #define _GNU_SOURCE +#include <alloca.h> #include <string.h> #include <stdio.h> #include <stdlib.h> @@ -328,11 +329,10 @@ char **backtrace_symbols(void *const *buffer, int size) /* discard calling function */ int total = 0; - char ***locations; char **final; char *f_strings; - locations = malloc(sizeof(char **) * (stack_depth+1)); + char ***const locations = alloca(sizeof(char **) * (stack_depth+1)); bfd_init(); for(x=stack_depth, y=0; x>=0; x--, y++){ @@ -363,7 +363,5 @@ char **backtrace_symbols(void *const *buffer, int size) f_strings += strlen(f_strings) + 1; } - free(locations); - return final; } @@ -218,14 +218,12 @@ static bool verify_frame(const char *s) { } static char* generate_stacktrace(void) { - void **buffer; char **strings, *ret, *p; int n, i; size_t k; bool b; - buffer = malloc(sizeof(void*) * frames_max); - assert(buffer); + void **const buffer = alloca(sizeof(void*) * frames_max); n = real_backtrace(buffer, frames_max); assert(n >= 0); @@ -233,8 +231,6 @@ static char* generate_stacktrace(void) { strings = real_backtrace_symbols(buffer, n); assert(strings); - free(buffer); - k = 0; for (i = 0; i < n; i++) k += strlen(strings[i]) + 2; |