diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-12-15 22:58:06 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:16:31 -0500 |
commit | 247e1667b00354d0407b8f3de2dc11ba751b1918 (patch) | |
tree | 891dc2cf42d835c79d5ec2c9392576c56217f56d /source3 | |
parent | b49f0ae01875a2f4fd8f56c8cd2d4ff42b998ef4 (diff) | |
download | samba-247e1667b00354d0407b8f3de2dc11ba751b1918.tar.gz samba-247e1667b00354d0407b8f3de2dc11ba751b1918.tar.bz2 samba-247e1667b00354d0407b8f3de2dc11ba751b1918.zip |
r20197: merge talloc fixes from samba4:
- make most static functions inline
- handle NULL pointers in talloc_parent_chunk()
- use talloc_parent_chunk() in talloc_parent_name()
to fix a bug found by the IBM checker
metze
(This used to be commit c718eb7a7c3cdc4acb25f303a73a3ca478c27af0)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/talloc/talloc.c | 36 | ||||
-rw-r--r-- | source3/lib/talloc/talloc.h | 2 |
2 files changed, 18 insertions, 20 deletions
diff --git a/source3/lib/talloc/talloc.c b/source3/lib/talloc/talloc.c index 91e02d7e1e..15a44bd0d9 100644 --- a/source3/lib/talloc/talloc.c +++ b/source3/lib/talloc/talloc.c @@ -162,10 +162,17 @@ do { \ /* return the parent chunk of a pointer */ -static struct talloc_chunk *talloc_parent_chunk(const void *ptr) +static inline struct talloc_chunk *talloc_parent_chunk(const void *ptr) { - struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); + struct talloc_chunk *tc; + + if (unlikely(ptr == NULL)) { + return NULL; + } + + tc = talloc_chunk_from_ptr(ptr); while (tc->prev) tc=tc->prev; + return tc->parent; } @@ -178,23 +185,12 @@ void *talloc_parent(const void *ptr) /* find parents name */ -const char *talloc_parent_name(const void *context) +const char *talloc_parent_name(const void *ptr) { - struct talloc_chunk *tc; - - if (unlikely(context == NULL)) { - return NULL; - } - - tc = talloc_chunk_from_ptr(context); - while (tc && tc->prev) tc = tc->prev; - if (tc) { - tc = tc->parent; - } - return tc->name; + struct talloc_chunk *tc = talloc_parent_chunk(ptr); + return tc? tc->name : NULL; } - /* Allocate a bit of memory as a child of an existing pointer */ @@ -265,6 +261,8 @@ int talloc_increase_ref_count(const void *ptr) /* helper for talloc_reference() + + this is referenced by a function pointer and should not be inline */ static int talloc_reference_destructor(struct talloc_reference_handle *handle) { @@ -481,7 +479,7 @@ void *_talloc_steal(const void *new_ctx, const void *ptr) talloc_reference() has done. The context and pointer arguments must match those given to a talloc_reference() */ -static int talloc_unreference(const void *context, const void *ptr) +static inline int talloc_unreference(const void *context, const void *ptr) { struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); struct talloc_reference_handle *h; @@ -561,9 +559,9 @@ int talloc_unlink(const void *context, void *ptr) /* add a name to an existing pointer - va_list version */ -static const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0); +static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0); -static const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) +static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) { struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); tc->name = talloc_vasprintf(ptr, fmt, ap); diff --git a/source3/lib/talloc/talloc.h b/source3/lib/talloc/talloc.h index 27d7d2c423..75c130a275 100644 --- a/source3/lib/talloc/talloc.h +++ b/source3/lib/talloc/talloc.h @@ -123,7 +123,7 @@ void *talloc_named_const(const void *context, size_t size, const char *name); const char *talloc_get_name(const void *ptr); void *talloc_check_name(const void *ptr, const char *name); void *talloc_parent(const void *ptr); -const char *talloc_parent_name(const void *context); +const char *talloc_parent_name(const void *ptr); void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); int talloc_free(void *ptr); void talloc_free_children(void *ptr); |