summaryrefslogtreecommitdiff
path: root/lib/talloc
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-03-12 08:19:50 +0100
committerStefan Metzmacher <metze@samba.org>2009-03-12 12:04:31 +0100
commit7a8b97ec2bcedb18b56b54fbf61eb0d6e9005193 (patch)
tree83a86bfd38ef7c32ce0d9f045407e5acec3c6157 /lib/talloc
parent1e4f78cc41d7d44703bea238fee86da618d1587b (diff)
downloadsamba-7a8b97ec2bcedb18b56b54fbf61eb0d6e9005193.tar.gz
samba-7a8b97ec2bcedb18b56b54fbf61eb0d6e9005193.tar.bz2
samba-7a8b97ec2bcedb18b56b54fbf61eb0d6e9005193.zip
talloc: add talloc_set_abort_fn()
metze
Diffstat (limited to 'lib/talloc')
-rw-r--r--lib/talloc/talloc.c35
-rw-r--r--lib/talloc/talloc.h2
2 files changed, 33 insertions, 4 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index c472e9fda9..60a48ad811 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -138,14 +138,30 @@ struct talloc_chunk {
#define TC_HDR_SIZE ((sizeof(struct talloc_chunk)+15)&~15)
#define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc))
+static void (*talloc_abort_fn)(const char *reason);
+
+void talloc_set_abort_fn(void (*abort_fn)(const char *reason))
+{
+ talloc_abort_fn = abort_fn;
+}
+
+static void talloc_abort(const char *reason)
+{
+ if (!talloc_abort_fn) {
+ TALLOC_ABORT(reason);
+ }
+
+ talloc_abort_fn(reason);
+}
+
static void talloc_abort_double_free(void)
{
- TALLOC_ABORT("Bad talloc magic value - double free");
+ talloc_abort("Bad talloc magic value - double free");
}
static void talloc_abort_unknown_value(void)
{
- TALLOC_ABORT("Bad talloc magic value - unknown value");
+ talloc_abort("Bad talloc magic value - unknown value");
}
/* panic if we get a bad magic value */
@@ -564,7 +580,7 @@ static inline int _talloc_free(void *ptr)
pool_object_count = talloc_pool_objectcount(pool);
if (*pool_object_count == 0) {
- TALLOC_ABORT("Pool object count zero!");
+ talloc_abort("Pool object count zero!");
}
*pool_object_count -= 1;
@@ -810,7 +826,18 @@ static void talloc_abort_type_missmatch(const char *location,
const char *name,
const char *expected)
{
- TALLOC_ABORT("Type missmatch");
+ const char *reason;
+
+ reason = talloc_asprintf(NULL,
+ "%s: Type mismatch: name[%s] expected[%s]",
+ location,
+ name?name:"NULL",
+ expected);
+ if (!reason) {
+ reason = "Type mismatch";
+ }
+
+ talloc_abort(reason);
}
void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location)
diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h
index 002e06e52d..b62393494b 100644
--- a/lib/talloc/talloc.h
+++ b/lib/talloc/talloc.h
@@ -182,4 +182,6 @@ char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3)
char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+void talloc_set_abort_fn(void (*abort_fn)(const char *reason));
+
#endif