summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/talloc/talloc.c27
-rw-r--r--source4/lib/talloc/talloc.h2
2 files changed, 22 insertions, 7 deletions
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c
index d480cc2689..ab199678c1 100644
--- a/source4/lib/talloc/talloc.c
+++ b/source4/lib/talloc/talloc.c
@@ -364,26 +364,29 @@ int talloc_unlink(const void *context, void *ptr)
/*
add a name to an existing pointer - va_list version
*/
-static void 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) PRINTF_ATTRIBUTE(2,0);
-static void talloc_set_name_v(const void *ptr, const char *fmt, va_list ap)
+static 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);
if (tc->name) {
talloc_set_name_const(tc->name, ".name");
}
+ return tc->name;
}
/*
add a name to an existing pointer
*/
-void talloc_set_name(const void *ptr, const char *fmt, ...)
+const char *talloc_set_name(const void *ptr, const char *fmt, ...)
{
+ const char *name;
va_list ap;
va_start(ap, fmt);
- talloc_set_name_v(ptr, fmt, ap);
+ name = talloc_set_name_v(ptr, fmt, ap);
va_end(ap);
+ return name;
}
/*
@@ -405,14 +408,20 @@ void *talloc_named(const void *context, size_t size, const char *fmt, ...)
{
va_list ap;
void *ptr;
+ const char *name;
ptr = _talloc(context, size);
if (ptr == NULL) return NULL;
va_start(ap, fmt);
- talloc_set_name_v(ptr, fmt, ap);
+ name = talloc_set_name_v(ptr, fmt, ap);
va_end(ap);
+ if (name == NULL) {
+ talloc_free(ptr);
+ return NULL;
+ }
+
return ptr;
}
@@ -474,14 +483,20 @@ void *talloc_init(const char *fmt, ...)
{
va_list ap;
void *ptr;
+ const char *name;
ptr = _talloc(NULL, 0);
if (ptr == NULL) return NULL;
va_start(ap, fmt);
- talloc_set_name_v(ptr, fmt, ap);
+ name = talloc_set_name_v(ptr, fmt, ap);
va_end(ap);
+ if (name == NULL) {
+ talloc_free(ptr);
+ return NULL;
+ }
+
return ptr;
}
diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h
index be2b305753..d71e60cb45 100644
--- a/source4/lib/talloc/talloc.h
+++ b/source4/lib/talloc/talloc.h
@@ -114,7 +114,7 @@ void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
void talloc_increase_ref_count(const void *ptr);
void *talloc_reference(const void *context, const void *ptr);
int talloc_unlink(const void *context, void *ptr);
-void talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
void talloc_set_name_const(const void *ptr, const char *name);
void *talloc_named(const void *context, size_t size,
const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);