From e73df517c877add667cc36e889282d129eebe3b9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 00:38:22 +0000 Subject: r25014: Use talloc for allocating values as well. (This used to be commit 43f0e2622ef61bd865fcf17191118c050ec8cfcb) --- source4/lib/util/util.h | 7 +------ source4/lib/util/util_str.c | 33 ++++++++++----------------------- 2 files changed, 11 insertions(+), 29 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 8d71ad1a64..a2e0954517 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -370,16 +370,11 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he */ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); -/** - Free a string value. -**/ -_PUBLIC_ void string_free(char **s); - /** Set a string value, deallocating any existing space, and allocing the space for the string **/ -_PUBLIC_ bool string_set(char **dest, const char *src); +_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src); /** Substitute a string for a pattern in another string. Make sure there is diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index eb8155cc7c..4bec469f87 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -260,36 +260,23 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ } /** - Set a string value, allocing the space for the string + Set a string value, deallocating any existing space, and allocing the space + for the string **/ -static bool string_init(char **dest,const char *src) +_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src) { - if (!src) src = ""; + talloc_free(*dest); - (*dest) = strdup(src); + if (src == NULL) + src = ""; + + *dest = talloc_strdup(mem_ctx, src); if ((*dest) == NULL) { DEBUG(0,("Out of memory in string_init\n")); return false; } - return true; -} - -/** - Free a string value. -**/ -_PUBLIC_ void string_free(char **s) -{ - if (s) SAFE_FREE(*s); -} -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ -_PUBLIC_ bool string_set(char **dest, const char *src) -{ - string_free(dest); - return string_init(dest,src); + return true; } /** @@ -304,7 +291,7 @@ _PUBLIC_ bool string_set(char **dest, const char *src) use of len==0 which was for no length checks to be done. **/ -_PUBLIC_ void string_sub(char *s,const char *pattern, const char *insert, size_t len) +_PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_t len) { char *p; ssize_t ls,lp,li, i; -- cgit