From 56a5d05b8b285250bdc0e9cc3c8f3c3d8af80382 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 02:51:26 +0000 Subject: [PATCH] r22590: Make TALLOC_ARRAY consistent across all uses. That should be it.... Jeremy. (This used to be commit 603233a98bbf65467c8b4f04719d771c70b3b4c9) --- source3/lib/secace.c | 8 ++++++-- source3/libads/dns.c | 12 ++++++++---- source3/libgpo/gpo_ldap.c | 28 ++++++++++++++++++++-------- source3/libmsrpc/libmsrpc_internal.c | 10 +++++++--- source3/nsswitch/idmap.c | 12 +++++++++--- source3/nsswitch/winbindd_ads.c | 23 ++++++++++++++--------- source3/registry/regfio.c | 8 ++++++-- source3/smbd/msdfs.c | 12 ++++++++---- source3/utils/net_rpc_samsync.c | 12 ++++++++---- 9 files changed, 86 insertions(+), 39 deletions(-) diff --git a/source3/lib/secace.c b/source3/lib/secace.c index d60722c57ee..871c983533d 100644 --- a/source3/lib/secace.c +++ b/source3/lib/secace.c @@ -122,8 +122,12 @@ NTSTATUS sec_ace_del_sid(TALLOC_CTX *ctx, SEC_ACE **pp_new, SEC_ACE *old, uint32 if (!ctx || !pp_new || !old || !sid || !num) return NT_STATUS_INVALID_PARAMETER; - if((pp_new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0) - return NT_STATUS_NO_MEMORY; + if (*num) { + if((pp_new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0) + return NT_STATUS_NO_MEMORY; + } else { + pp_new[0] = NULL; + } for (i = 0; i < *num; i ++) { if (sid_compare(&old[i].trustee, sid) != 0) diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 8b031b0e3a7..f16cea25554 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -355,10 +355,14 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn DEBUG(4,("ads_dns_lookup_srv: %d records returned in the answer section.\n", answer_count)); - if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { - DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", - answer_count)); - return NT_STATUS_NO_MEMORY; + if (answer_count) { + if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", + answer_count)); + return NT_STATUS_NO_MEMORY; + } + } else { + dcs = NULL; } /* now skip the header */ diff --git a/source3/libgpo/gpo_ldap.c b/source3/libgpo/gpo_ldap.c index 13ec80f2ad2..6c1079832d0 100644 --- a/source3/libgpo/gpo_ldap.c +++ b/source3/libgpo/gpo_ldap.c @@ -47,12 +47,17 @@ ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx, gp_ext->num_exts = i; - gp_ext->extensions = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); - gp_ext->extensions_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); - gp_ext->snapins = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); - gp_ext->snapins_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); - - gp_ext->gp_extension = talloc_strdup(mem_ctx, extension_raw); + if (gp_ext->num_exts) { + gp_ext->extensions = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); + gp_ext->extensions_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); + gp_ext->snapins = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); + gp_ext->snapins_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts); + } else { + gp_ext->extensions = NULL; + gp_ext->extensions_guid = NULL; + gp_ext->snapins = NULL; + gp_ext->snapins_guid = NULL; + } if (gp_ext->extensions == NULL || gp_ext->extensions_guid == NULL || gp_ext->snapins == NULL || gp_ext->snapins_guid == NULL || @@ -60,6 +65,8 @@ ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx, goto parse_error; } + gp_ext->gp_extension = talloc_strdup(mem_ctx, extension_raw); + for (i = 0; ext_list[i] != NULL; i++) { int k; @@ -161,8 +168,13 @@ ADS_STATUS ads_parse_gplink(TALLOC_CTX *mem_ctx, gp_link->gp_opts = options; gp_link->num_links = i; - gp_link->link_names = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_link->num_links); - gp_link->link_opts = TALLOC_ZERO_ARRAY(mem_ctx, uint32, gp_link->num_links); + if (gp_link->num_links) { + gp_link->link_names = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_link->num_links); + gp_link->link_opts = TALLOC_ZERO_ARRAY(mem_ctx, uint32, gp_link->num_links); + } else { + gp_link->link_names = NULL; + gp_link->link_opts = NULL; + } gp_link->gp_link = talloc_strdup(mem_ctx, gp_link_raw); diff --git a/source3/libmsrpc/libmsrpc_internal.c b/source3/libmsrpc/libmsrpc_internal.c index 3cb702e3767..a06915b72c7 100644 --- a/source3/libmsrpc/libmsrpc_internal.c +++ b/source3/libmsrpc/libmsrpc_internal.c @@ -713,9 +713,13 @@ CacService *cac_MakeServiceArray( TALLOC_CTX * mem_ctx, if ( !mem_ctx || !svc ) return NULL; - services = TALLOC_ZERO_ARRAY( mem_ctx, CacService, num_services ); - if ( !services ) - return NULL; + if (num_services) { + services = TALLOC_ZERO_ARRAY( mem_ctx, CacService, num_services ); + if ( !services ) + return NULL; + } else { + services = NULL; + } for ( i = 0; i < num_services; i++ ) { services[i].service_name = diff --git a/source3/nsswitch/idmap.c b/source3/nsswitch/idmap.c index 26fcc692e9e..5222eba8f36 100644 --- a/source3/nsswitch/idmap.c +++ b/source3/nsswitch/idmap.c @@ -1026,9 +1026,15 @@ static NTSTATUS idmap_backends_sids_to_unixids(struct id_map **ids) /* split list per domain */ - dom_ids = TALLOC_ZERO_ARRAY(ctx, struct id_map **, num_domains); - IDMAP_CHECK_ALLOC(dom_ids); - counters = TALLOC_ZERO_ARRAY(ctx, int, num_domains); + if (num_domains) { + dom_ids = TALLOC_ZERO_ARRAY(ctx, struct id_map **, num_domains); + IDMAP_CHECK_ALLOC(dom_ids); + counters = TALLOC_ZERO_ARRAY(ctx, int, num_domains); + IDMAP_CHECK_ALLOC(counters); + } else { + dom_ids = NULL; + counters = NULL; + } /* partition the requests by domain */ diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 01174edf37e..355a0938557 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -907,16 +907,21 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, the problem is that the members are in the form of distinguised names */ - (*sid_mem) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_members); - (*name_types) = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_members); - (*names) = TALLOC_ZERO_ARRAY(mem_ctx, char *, num_members); + if (num_members) { + (*sid_mem) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_members); + (*name_types) = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_members); + (*names) = TALLOC_ZERO_ARRAY(mem_ctx, char *, num_members); - if ((num_members != 0) && - ((members == NULL) || (*sid_mem == NULL) || - (*name_types == NULL) || (*names == NULL))) { - DEBUG(1, ("talloc failed\n")); - status = NT_STATUS_NO_MEMORY; - goto done; + if ((members == NULL) || (*sid_mem == NULL) || + (*name_types == NULL) || (*names == NULL)) { + DEBUG(1, ("talloc failed\n")); + status = NT_STATUS_NO_MEMORY; + goto done; + } + } else { + (*sid_mem) = NULL; + (*name_types) = NULL; + (*names) = NULL; } for (i=0;isubkeys.header, "lf", REC_HDR_SIZE ); nk->subkeys.num_keys = nk->num_subkeys; - if ( !(nk->subkeys.hashes = TALLOC_ZERO_ARRAY( file->mem_ctx, REGF_HASH_REC, nk->subkeys.num_keys )) ) - return NULL; + if (nk->subkeys.num_keys) { + if ( !(nk->subkeys.hashes = TALLOC_ZERO_ARRAY( file->mem_ctx, REGF_HASH_REC, nk->subkeys.num_keys )) ) + return NULL; + } else { + nk->subkeys.hashes = NULL; + } nk->subkey_index = 0; /* update the max_bytes_subkey{name,classname} fields */ diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index effe868657e..9f203bfd190 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -264,10 +264,14 @@ static BOOL parse_msdfs_symlink(TALLOC_CTX *ctx, DEBUG(10,("parse_msdfs_symlink: count=%d\n", count)); - reflist = *preflist = TALLOC_ZERO_ARRAY(ctx, struct referral, count); - if(reflist == NULL) { - DEBUG(0,("parse_msdfs_symlink: talloc failed!\n")); - return False; + if (count) { + reflist = *preflist = TALLOC_ZERO_ARRAY(ctx, struct referral, count); + if(reflist == NULL) { + DEBUG(0,("parse_msdfs_symlink: talloc failed!\n")); + return False; + } + } else { + reflist = *preflist = NULL; } for(i=0;inum_members)) == NULL) { - DEBUG(0, ("talloc failed\n")); - talloc_free(t); - return NT_STATUS_NO_MEMORY; + if (delta->num_members) { + if ((nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members)) == NULL) { + DEBUG(0, ("talloc failed\n")); + talloc_free(t); + return NT_STATUS_NO_MEMORY; + } + } else { + nt_members = NULL; } for (i=0; inum_members; i++) {