diff options
author | Kai Blin <kai@samba.org> | 2008-01-19 02:12:35 +0100 |
---|---|---|
committer | Kai Blin <kai@samba.org> | 2008-01-19 02:20:16 +0100 |
commit | 805caafd44cbc5fff49711b1a15fb64cc99f3ad3 (patch) | |
tree | 54c96bb7e84de810b3199b3a444ae27adef6d626 /source3/lib | |
parent | b97fbf58886427fbb7f3181694bf6f9648f5d0f4 (diff) | |
download | samba-805caafd44cbc5fff49711b1a15fb64cc99f3ad3.tar.gz samba-805caafd44cbc5fff49711b1a15fb64cc99f3ad3.tar.bz2 samba-805caafd44cbc5fff49711b1a15fb64cc99f3ad3.zip |
util_str: Don't return memory from talloc_tos(), use mem_ctx instead.
(This used to be commit ab0ee6e9a6a9eee317228f0c2bde254ad9a59b85)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/afs.c | 23 | ||||
-rw-r--r-- | source3/lib/util_str.c | 6 |
2 files changed, 16 insertions, 13 deletions
diff --git a/source3/lib/afs.c b/source3/lib/afs.c index a7d6f6c9f7..b3d590bf24 100644 --- a/source3/lib/afs.c +++ b/source3/lib/afs.c @@ -42,20 +42,23 @@ static char *afs_encode_token(const char *cell, const DATA_BLOB ticket, const struct ClearToken *ct) { char *base64_ticket; - char *result; + char *result = NULL; DATA_BLOB key = data_blob(ct->HandShakeKey, 8); char *base64_key; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("afs_encode_token"); + if (mem_ctx == NULL) + goto done; - base64_ticket = base64_encode_data_blob(ticket); + base64_ticket = base64_encode_data_blob(mem_ctx, ticket); if (base64_ticket == NULL) - return NULL; + goto done; - base64_key = base64_encode_data_blob(key); - if (base64_key == NULL) { - TALLOC_FREE(base64_ticket); - return NULL; - } + base64_key = base64_encode_data_blob(mem_ctx, key); + if (base64_key == NULL) + goto done; asprintf(&result, "%s\n%u\n%s\n%u\n%u\n%u\n%s\n", cell, ct->AuthHandle, base64_key, ct->ViceId, ct->BeginTimestamp, @@ -63,8 +66,8 @@ static char *afs_encode_token(const char *cell, const DATA_BLOB ticket, DEBUG(10, ("Got ticket string:\n%s\n", result)); - TALLOC_FREE(base64_ticket); - TALLOC_FREE(base64_key); +done: + TALLOC_FREE(mem_ctx); return result; } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 3e3268104c..bcb9197141 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -2415,13 +2415,13 @@ void base64_decode_inplace(char *s) } /** - * Encode a base64 string into a malloc()ed string caller to free. + * Encode a base64 string into a talloc()ed string caller to free. * * From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c * with adjustments **/ -char *base64_encode_data_blob(DATA_BLOB data) +char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data) { int bits = 0; int char_count = 0; @@ -2434,7 +2434,7 @@ char *base64_encode_data_blob(DATA_BLOB data) out_cnt = 0; len = data.length; output_len = data.length * 2; - result = TALLOC_ARRAY(talloc_tos(), char, output_len); /* get us plenty of space */ + result = TALLOC_ARRAY(mem_ctx, char, output_len); /* get us plenty of space */ SMB_ASSERT(result != NULL); while (len-- && out_cnt < (data.length * 2) - 5) { |