svn commit: samba r16712 - in trunk/source: include lib libndr
passdb
vlendec at samba.org
vlendec at samba.org
Fri Jun 30 15:32:35 GMT 2006
Author: vlendec
Date: 2006-06-30 15:32:33 +0000 (Fri, 30 Jun 2006)
New Revision: 16712
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16712
Log:
Get rid of the remaining talloc_steal references.
First I was a bit annoyed by Jeremy whining about it, but going through the
code I must admit that the code has only slightly grown in size while it has
gained in clarity.
talloc_steal() is still there, but I made it static in lib/talloc.c. So if
someone *really* needs it, the code is still around.
Volker
Modified:
trunk/source/include/talloc.h
trunk/source/lib/talloc.c
trunk/source/lib/talloctort.c
trunk/source/libndr/ndr.c
trunk/source/passdb/lookup_sid.c
Changeset:
Modified: trunk/source/include/talloc.h
===================================================================
--- trunk/source/include/talloc.h 2006-06-30 14:59:27 UTC (rev 16711)
+++ trunk/source/include/talloc.h 2006-06-30 15:32:33 UTC (rev 16712)
@@ -114,7 +114,7 @@
void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
int talloc_free(void *ptr);
void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
-void *talloc_steal(const void *new_ctx, const void *ptr);
+/* void *talloc_steal(const void *new_ctx, const void *ptr); */
off_t talloc_total_size(const void *ptr);
off_t talloc_total_blocks(const void *ptr);
void talloc_report_full(const void *ptr, FILE *f);
Modified: trunk/source/lib/talloc.c
===================================================================
--- trunk/source/lib/talloc.c 2006-06-30 14:59:27 UTC (rev 16711)
+++ trunk/source/lib/talloc.c 2006-06-30 15:32:33 UTC (rev 16712)
@@ -85,6 +85,7 @@
static const void *null_context;
static void *cleanup_context;
+static void *talloc_steal(const void *new_ctx, const void *ptr);
struct talloc_reference_handle {
struct talloc_reference_handle *next, *prev;
@@ -665,7 +666,7 @@
ptr on success, or NULL if it could not be transferred.
passing NULL as ptr will always return NULL with no side effects.
*/
-void *talloc_steal(const void *new_ctx, const void *ptr)
+static void *talloc_steal(const void *new_ctx, const void *ptr)
{
struct talloc_chunk *tc, *new_tc;
Modified: trunk/source/lib/talloctort.c
===================================================================
--- trunk/source/lib/talloctort.c 2006-06-30 14:59:27 UTC (rev 16711)
+++ trunk/source/lib/talloctort.c 2006-06-30 15:32:33 UTC (rev 16712)
@@ -656,6 +656,7 @@
return True;
}
+#if 0
/*
test steal
*/
@@ -709,6 +710,7 @@
return True;
}
+#endif
/*
test talloc_realloc_fn
@@ -819,7 +821,7 @@
ret &= test_misc();
ret &= test_realloc();
ret &= test_realloc_child();
- ret &= test_steal();
+/* ret &= test_steal(); */
ret &= test_unref_reparent();
ret &= test_realloc_fn();
ret &= test_type();
Modified: trunk/source/libndr/ndr.c
===================================================================
--- trunk/source/libndr/ndr.c 2006-06-30 14:59:27 UTC (rev 16711)
+++ trunk/source/libndr/ndr.c 2006-06-30 15:32:33 UTC (rev 16712)
@@ -275,16 +275,15 @@
ndr = talloc_zero(mem_ctx, struct ndr_print);
if (!ndr) return NULL;
- ndr->private_data = talloc_strdup(ndr, "");
- if (!ndr->private_data) {
- goto failed;
+ if (!(ndr->private_data = talloc_strdup(mem_ctx, ""))) {
+ TALLOC_FREE(ndr);
+ return NULL;
}
ndr->print = ndr_print_string_helper;
ndr->depth = 1;
ndr->flags = 0;
fn(ndr, name, flags, ptr);
- ret = talloc_steal(mem_ctx, ndr->private_data);
-failed:
+ ret = ndr->private_data;
talloc_free(ndr);
return ret;
}
Modified: trunk/source/passdb/lookup_sid.c
===================================================================
--- trunk/source/passdb/lookup_sid.c 2006-06-30 14:59:27 UTC (rev 16711)
+++ trunk/source/passdb/lookup_sid.c 2006-06-30 15:32:33 UTC (rev 16712)
@@ -664,18 +664,17 @@
int i, j;
- tmp_ctx = talloc_new(mem_ctx);
- if (tmp_ctx == NULL) {
+ if (!(tmp_ctx = talloc_new(mem_ctx))) {
DEBUG(0, ("talloc_new failed\n"));
return NT_STATUS_NO_MEMORY;
}
- name_infos = TALLOC_ARRAY(tmp_ctx, struct lsa_name_info, num_sids);
- dom_infos = TALLOC_ZERO_ARRAY(tmp_ctx, struct lsa_dom_info,
+ name_infos = TALLOC_ARRAY(mem_ctx, struct lsa_name_info, num_sids);
+ dom_infos = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_dom_info,
MAX_REF_DOMAINS);
if ((name_infos == NULL) || (dom_infos == NULL)) {
result = NT_STATUS_NO_MEMORY;
- goto done;
+ goto fail;
}
/* First build up the data structures:
@@ -710,7 +709,7 @@
*/
if (domain_name == NULL) {
result = NT_STATUS_NO_MEMORY;
- goto done;
+ goto fail;
}
name_infos[i].rid = 0;
@@ -724,14 +723,14 @@
name_infos, builtin_domain_name());
if (name_infos[i].name == NULL) {
result = NT_STATUS_NO_MEMORY;
- goto done;
+ goto fail;
}
}
} else {
/* This is a normal SID with rid component */
if (!sid_split_rid(&sid, &rid)) {
result = NT_STATUS_INVALID_PARAMETER;
- goto done;
+ goto fail;
}
}
@@ -754,7 +753,7 @@
if (j == MAX_REF_DOMAINS) {
/* TODO: What's the right error message here? */
result = NT_STATUS_NONE_MAPPED;
- goto done;
+ goto fail;
}
if (!dom_infos[j].valid) {
@@ -767,7 +766,11 @@
/* This name was being found above in the case
* when we found a domain SID */
dom_infos[j].name =
- talloc_steal(dom_infos, domain_name);
+ talloc_strdup(dom_infos, domain_name);
+ if (dom_infos[j].name == NULL) {
+ result = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
} else {
/* lookup_rids will take care of this */
dom_infos[j].name = NULL;
@@ -784,7 +787,7 @@
if (dom_infos[j].idxs == NULL) {
result = NT_STATUS_NO_MEMORY;
- goto done;
+ goto fail;
}
}
}
@@ -793,6 +796,7 @@
for (i=0; i<MAX_REF_DOMAINS; i++) {
uint32_t *rids;
+ const char *domain_name = NULL;
const char **names;
enum SID_NAME_USE *types;
struct lsa_dom_info *dom = &dom_infos[i];
@@ -802,11 +806,9 @@
break;
}
- rids = TALLOC_ARRAY(tmp_ctx, uint32, dom->num_idxs);
-
- if (rids == NULL) {
+ if (!(rids = TALLOC_ARRAY(tmp_ctx, uint32, dom->num_idxs))) {
result = NT_STATUS_NO_MEMORY;
- goto done;
+ goto fail;
}
for (j=0; j<dom->num_idxs; j++) {
@@ -814,31 +816,40 @@
}
if (!lookup_rids(tmp_ctx, &dom->sid,
- dom->num_idxs, rids, &dom->name,
+ dom->num_idxs, rids, &domain_name,
&names, &types)) {
result = NT_STATUS_NO_MEMORY;
- goto done;
+ goto fail;
}
- talloc_steal(dom_infos, dom->name);
-
+ if (!(dom->name = talloc_strdup(dom_infos, domain_name))) {
+ result = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
for (j=0; j<dom->num_idxs; j++) {
int idx = dom->idxs[j];
name_infos[idx].type = types[j];
if (types[j] != SID_NAME_UNKNOWN) {
name_infos[idx].name =
- talloc_steal(name_infos, names[j]);
+ talloc_strdup(name_infos, names[j]);
+ if (name_infos[idx].name == NULL) {
+ result = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
} else {
name_infos[idx].name = NULL;
}
}
}
- *ret_domains = talloc_steal(mem_ctx, dom_infos);
- *ret_names = talloc_steal(mem_ctx, name_infos);
- result = NT_STATUS_OK;
+ *ret_domains = dom_infos;
+ *ret_names = name_infos;
+ return NT_STATUS_OK;
- done:
+ fail:
+ TALLOC_FREE(dom_infos);
+ TALLOC_FREE(name_infos);
TALLOC_FREE(tmp_ctx);
return result;
}
More information about the samba-cvs
mailing list