1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

talloc: add talloc_set_abort_fn()

metze
This commit is contained in:
Stefan Metzmacher 2009-03-12 08:19:50 +01:00
parent 1e4f78cc41
commit 7a8b97ec2b
2 changed files with 33 additions and 4 deletions

View File

@ -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)

View File

@ -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