X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ftalloc%2Ftalloc.c;h=e275fb0bf5da695a9eeed354fee146a5d03321c1;hb=HEAD;hp=c660870543a83ff4d6dcee74ac516f599bd0709b;hpb=32e6a41f33e5576716b351bd473a27939fe94fa1;p=petitboot diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index c660870..e275fb0 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -26,19 +26,21 @@ inspired by http://swapped.cc/halloc/ */ - +#if defined(HAVE_CONFIG_H) #include "config.h" - -#include -#include -#include - +#else /* nfsim additions */ #define HAVE_SYS_TYPES_H #define HAVE_UNISTD_H #define HAVE_STDARG_H #define HAVE_STDINT_H #define HAVE_VA_COPY +#endif + +#include +#include +#include +#include #ifdef HAVE_SYS_TYPES_H #include @@ -58,6 +60,7 @@ #include #endif +#include "log/log.h" #include "talloc.h" /* use this to force every realloc to change the pointer, to stress test @@ -70,12 +73,6 @@ #define TALLOC_MAGIC_FREE 0x7faebef3 #define TALLOC_MAGIC_REFERENCE ((const char *)1) -/* by default we abort when given a bad pointer (such as when talloc_free() is - * called on a pointer that came from malloc() */ -#ifndef TALLOC_ABORT -#define TALLOC_ABORT(reason) abort() -#endif - #ifndef discard_const_p #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) # define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr))) @@ -118,10 +115,16 @@ static struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr) struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, ptr)-1; if (tc->u.magic != TALLOC_MAGIC) { if (tc->u.magic == TALLOC_MAGIC_FREE) { - TALLOC_ABORT("Bad talloc magic value - double free"); + pb_log_fn("Failed: Bad talloc magic value - double free, for name: %s\n", + tc->name); + fprintf(stderr, "%s: name: %s\n", __func__, tc->name); + fflush(stderr); + assert(0 && "Bad talloc magic value - double free"); } else { - TALLOC_ABORT("Bad talloc magic value - unknown value"); + pb_log_fn("Failed: Bad talloc magic value - unknown value\n"); + assert(0 && "Bad talloc magic value - unknown value"); } + abort(); } return tc; @@ -752,7 +755,7 @@ off_t talloc_total_blocks(const void *ptr) /* return the number of external references to a pointer */ -static int talloc_reference_count(const void *ptr) +int talloc_reference_count(const void *ptr) { struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); struct talloc_reference_handle *h; @@ -976,6 +979,7 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) talloc_set_name_const(ret, ret); } + va_end(ap2); return ret; } @@ -1023,13 +1027,16 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(NULL, s, char, s_len + len+1); - if (!s) return NULL; + if (!s) + goto out; VA_COPY(ap2, ap); vsnprintf(s+s_len, len+1, fmt, ap2); talloc_set_name_const(s, s); +out: + va_end(ap2); return s; }