diff options
author | Andrew Bartlett <abartlet@samba.org> | 2004-11-05 12:20:27 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:05:31 -0500 |
commit | 438a54b8b4df147405bba0b3b55a895d81a27b8a (patch) | |
tree | 4b929a469a56952371da37ce5a82afe024ebaebd /source4/lib | |
parent | 8a5c9c28410ae0320356fe1686ad0ee7d1ec0e7b (diff) | |
download | samba-438a54b8b4df147405bba0b3b55a895d81a27b8a.tar.gz samba-438a54b8b4df147405bba0b3b55a895d81a27b8a.tar.bz2 samba-438a54b8b4df147405bba0b3b55a895d81a27b8a.zip |
r3553: Allow talloc_reference to take a NULL pointer for the "ptr" argument.
This allows potentially NULL pointers to be referenced, without an if ()
for every use. (previously, it would segfault).
Update doco, and allow talloc_unlink to match.
Andrew Bartlett
(This used to be commit 59757c7f9d0e08e3acacfb3116f6205057d5b119)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/talloc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/source4/lib/talloc.c b/source4/lib/talloc.c index 131edfcb81..239958258b 100644 --- a/source4/lib/talloc.c +++ b/source4/lib/talloc.c @@ -222,9 +222,13 @@ static int talloc_reference_destructor(void *ptr) */ void *talloc_reference(const void *context, const void *ptr) { - struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); + struct talloc_chunk *tc; struct talloc_reference_handle *handle; + if (ptr == NULL) return NULL; + + tc = talloc_chunk_from_ptr(ptr); handle = talloc_named_const(context, sizeof(*handle), TALLOC_MAGIC_REFERENCE); + if (handle == NULL) return NULL; /* note that we hang the destructor off the handle, not the @@ -273,6 +277,10 @@ int talloc_unlink(const void *context, void *ptr) struct talloc_chunk *tc_p, *new_p; void *new_parent; + if (ptr == NULL) { + return -1; + } + if (context == NULL) { context = null_context; } |