summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-06-21 19:28:24 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:09:15 -0500
commit816c055123ab2706ec09811e6375e6e8d8c8dd13 (patch)
tree67166e9a218e5ab1da651e49d59665b44293b56c /source4/lib
parent3a0a00f1b99757976218924b14082ce765ca1d7c (diff)
downloadsamba-816c055123ab2706ec09811e6375e6e8d8c8dd13.tar.gz
samba-816c055123ab2706ec09811e6375e6e8d8c8dd13.tar.bz2
samba-816c055123ab2706ec09811e6375e6e8d8c8dd13.zip
r16446: talloc_set_name() allocates and can fail...
pass the error to the callers metze (This used to be commit 7aa07a1e0b2abd1a6ecd490410685d20c0201094)
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);