summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/talloc.c10
-rw-r--r--source4/torture/local/talloc.c12
2 files changed, 20 insertions, 2 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;
}
diff --git a/source4/torture/local/talloc.c b/source4/torture/local/talloc.c
index 348b037753..2eedb2b9b0 100644
--- a/source4/torture/local/talloc.c
+++ b/source4/torture/local/talloc.c
@@ -117,6 +117,11 @@ static BOOL test_ref1(void)
talloc_free(r1);
talloc_report_full(NULL, stdout);
+ printf("Testing NULL\n");
+ if (talloc_reference(root, NULL)) {
+ return False;
+ }
+
CHECK_BLOCKS(root, 1);
CHECK_SIZE(root, 0);
@@ -478,7 +483,12 @@ static BOOL test_misc(void)
talloc_unlink(NULL, p2);
talloc_unlink(root, p1);
-
+ /* Test that talloc_unlink is a no-op */
+
+ if (talloc_unlink(root, NULL) != -1) {
+ printf("failed: talloc_unlink(root, NULL) == -1\n");
+ return False;
+ }
talloc_report(root, stdout);
talloc_report(NULL, stdout);