diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-03-20 01:30:36 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-03-20 01:30:36 +0100 |
commit | 5fe2b28f45289dc5578cdd536600f0d30a14d820 (patch) | |
tree | 4bdf36d0d4d8bdddcb3d618b4b01839370ed57c3 /lib/talloc/talloc.c | |
parent | ec9aeeab00584f4d3dfe9afb83dc1a77b8463b81 (diff) | |
parent | 3a4638db0351368d3b148bf547546f28fa0b1479 (diff) | |
download | samba-5fe2b28f45289dc5578cdd536600f0d30a14d820.tar.gz samba-5fe2b28f45289dc5578cdd536600f0d30a14d820.tar.bz2 samba-5fe2b28f45289dc5578cdd536600f0d30a14d820.zip |
Merge branch 'master' of git://git.samba.org/samba into minschema
Diffstat (limited to 'lib/talloc/talloc.c')
-rw-r--r-- | lib/talloc/talloc.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index 1f7e52439f..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; @@ -806,6 +822,41 @@ void *talloc_check_name(const void *ptr, const char *name) return NULL; } +static void talloc_abort_type_missmatch(const char *location, + const char *name, + const char *expected) +{ + 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) +{ + const char *pname; + + if (unlikely(ptr == NULL)) { + talloc_abort_type_missmatch(location, NULL, name); + return NULL; + } + + pname = talloc_get_name(ptr); + if (likely(pname == name || strcmp(pname, name) == 0)) { + return discard_const_p(void, ptr); + } + + talloc_abort_type_missmatch(location, pname, name); + return NULL; +} /* this is for compatibility with older versions of talloc |