diff options
author | Jeremy Allison <jra@samba.org> | 2004-12-07 18:25:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:53:32 -0500 |
commit | acf9d61421faa6c0055d57fdee7db300dc5431aa (patch) | |
tree | 5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/rpc_client | |
parent | 3bd3be97dc8a581c0502410453091c195e322766 (diff) | |
download | samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.gz samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.bz2 samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.zip |
r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
functions so we can funnel through some well known functions. Should help greatly with
malloc checking.
HEAD patch to follow.
Jeremy.
(This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a)
Diffstat (limited to 'source3/rpc_client')
-rw-r--r-- | source3/rpc_client/cli_ds.c | 24 | ||||
-rw-r--r-- | source3/rpc_client/cli_echo.c | 38 | ||||
-rw-r--r-- | source3/rpc_client/cli_lsarpc.c | 43 | ||||
-rw-r--r-- | source3/rpc_client/cli_samr.c | 20 | ||||
-rw-r--r-- | source3/rpc_client/cli_spoolss.c | 36 | ||||
-rw-r--r-- | source3/rpc_client/cli_srvsvc.c | 12 |
6 files changed, 94 insertions, 79 deletions
diff --git a/source3/rpc_client/cli_ds.c b/source3/rpc_client/cli_ds.c index 09e63a4714..1a2174d58c 100644 --- a/source3/rpc_client/cli_ds.c +++ b/source3/rpc_client/cli_ds.c @@ -39,8 +39,13 @@ NTSTATUS cli_ds_getprimarydominfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + return NT_STATUS_NO_MEMORY; + } + if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { + prs_mem_free(&qbuf); + return NT_STATUS_NO_MEMORY; + } q.level = level; @@ -63,7 +68,7 @@ NTSTATUS cli_ds_getprimarydominfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, result = r.status; if ( r.ptr && ctr ) { - ctr->basic = talloc(mem_ctx, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC)); + ctr->basic = TALLOC_P(mem_ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC); if (!ctr->basic) goto done; memcpy(ctr->basic, r.info.basic, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC)); @@ -94,8 +99,13 @@ NTSTATUS cli_ds_enum_domain_trusts(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + return NT_STATUS_NO_MEMORY;; + } + if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { + prs_mem_free(&qbuf); + return NT_STATUS_NO_MEMORY; + } init_q_ds_enum_domain_trusts( &q, server, flags ); @@ -118,7 +128,7 @@ NTSTATUS cli_ds_enum_domain_trusts(struct cli_state *cli, TALLOC_CTX *mem_ctx, int i; *num_domains = r.num_domains; - *trusts = (struct ds_domain_trust*)talloc(mem_ctx, r.num_domains*sizeof(**trusts)); + *trusts = TALLOC_ARRAY(mem_ctx, struct ds_domain_trust, r.num_domains); for ( i=0; i< *num_domains; i++ ) { (*trusts)[i].flags = r.domains.trusts[i].flags; @@ -153,5 +163,3 @@ done: return result; } - - diff --git a/source3/rpc_client/cli_echo.c b/source3/rpc_client/cli_echo.c index 03a4ab36ee..1ae7aaa8e7 100644 --- a/source3/rpc_client/cli_echo.c +++ b/source3/rpc_client/cli_echo.c @@ -35,8 +35,13 @@ NTSTATUS cli_echo_add_one(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + return NT_STATUS_NO_MEMORY; + } + if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { + prs_mem_free(&qbuf); + return NT_STATUS_NO_MEMORY; + } /* Marshall data and send request */ @@ -76,8 +81,13 @@ NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + return NT_STATUS_NO_MEMORY; + } + if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { + prs_mem_free(&qbuf); + return NT_STATUS_NO_MEMORY; + } /* Marshall data and send request */ @@ -95,7 +105,7 @@ NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, result = True; if (out_data) { - *out_data = talloc(mem_ctx, size); + *out_data = TALLOC(mem_ctx, size); memcpy(*out_data, r.data, size); } @@ -119,8 +129,13 @@ NTSTATUS cli_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + return NT_STATUS_NO_MEMORY; + } + if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { + prs_mem_free(&qbuf); + return NT_STATUS_NO_MEMORY; + } /* Marshall data and send request */ @@ -159,8 +174,13 @@ NTSTATUS cli_echo_source_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + return NT_STATUS_NO_MEMORY; + } + if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { + prs_mem_free(&qbuf); + return NT_STATUS_NO_MEMORY; + } /* Marshall data and send request */ diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c index 40b83c5c0c..a8dfa93bd8 100644 --- a/source3/rpc_client/cli_lsarpc.c +++ b/source3/rpc_client/cli_lsarpc.c @@ -88,7 +88,7 @@ NTSTATUS cli_lsa_open_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (NT_STATUS_IS_OK(result = r.status)) { *pol = r.pol; #ifdef __INSURE__ - pol->marker = malloc(1); + pol->marker = MALLOC(1); #endif } @@ -276,22 +276,19 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, goto done; } - if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) * - num_sids))) { + if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) * - num_sids))) { + if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) * - num_sids))) { + if (!((*types) = TALLOC_ARRAY(mem_ctx, uint32, num_sids))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; @@ -393,15 +390,13 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx, goto done; } - if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * - num_names)))) { + if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) * - num_names)))) { + if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; @@ -491,7 +486,7 @@ NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx, } if (domain_sid && (r.dom.id3.buffer_dom_sid != 0)) { - *domain_sid = talloc(mem_ctx, sizeof(**domain_sid)); + *domain_sid = TALLOC_P(mem_ctx, DOM_SID); if (*domain_sid) { sid_copy(*domain_sid, &r.dom.id3.dom_sid.sid); } @@ -508,7 +503,7 @@ NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx, } if (domain_sid && (r.dom.id5.buffer_dom_sid != 0)) { - *domain_sid = talloc(mem_ctx, sizeof(**domain_sid)); + *domain_sid = TALLOC_P(mem_ctx, DOM_SID); if (*domain_sid) { sid_copy(*domain_sid, &r.dom.id5.dom_sid.sid); } @@ -599,14 +594,14 @@ NTSTATUS cli_lsa_query_info_policy2(struct cli_state *cli, TALLOC_CTX *mem_ctx, } if (domain_guid) { - *domain_guid = talloc(mem_ctx, sizeof(**domain_guid)); + *domain_guid = TALLOC_P(mem_ctx, struct uuid); memcpy(*domain_guid, &r.info.dns_dom_info.dom_guid, sizeof(struct uuid)); } if (domain_sid && r.info.dns_dom_info.ptr_dom_sid != 0) { - *domain_sid = talloc(mem_ctx, sizeof(**domain_sid)); + *domain_sid = TALLOC_P(mem_ctx, DOM_SID); if (*domain_sid) { sid_copy(*domain_sid, &r.info.dns_dom_info.dom_sid.sid); @@ -689,8 +684,7 @@ NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Allocate memory for trusted domain names and sids */ - *domain_names = (char **)talloc(mem_ctx, sizeof(char *) * - r.num_domains); + *domain_names = TALLOC_ARRAY(mem_ctx, char *, r.num_domains); if (!*domain_names) { DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n")); @@ -698,8 +692,7 @@ NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx, goto done; } - *domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * - r.num_domains); + *domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.num_domains); if (!domain_sids) { DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n")); result = NT_STATUS_NO_MEMORY; @@ -775,19 +768,19 @@ NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx, *enum_context = r.enum_context; *count = r.count; - if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) { + if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) { DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) { + if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) { DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) { + if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) { DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; @@ -912,7 +905,7 @@ NTSTATUS cli_lsa_enum_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Return output parameters */ - *sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries); + *sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries); if (!*sids) { DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; @@ -1037,7 +1030,7 @@ NTSTATUS cli_lsa_enum_privsaccount(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (r.count == 0) goto done; - if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) { + if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) { DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; @@ -1206,7 +1199,7 @@ NTSTATUS cli_lsa_enum_account_rights(struct cli_state *cli, TALLOC_CTX *mem_ctx, goto done; } - *privs_name = (char **)talloc(mem_ctx, (*count) * sizeof(char **)); + *privs_name = TALLOC_ARRAY(mem_ctx, char *, *count); for (i=0;i<*count;i++) { pull_ucs2_talloc(mem_ctx, &(*privs_name)[i], r.rights.strings[i].string.buffer); } diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c index 86f6505689..26c29474ea 100644 --- a/source3/rpc_client/cli_samr.c +++ b/source3/rpc_client/cli_samr.c @@ -853,13 +853,13 @@ NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (r.num_entries2) { /* allocate memory needed to return received data */ - *rids = (uint32*)talloc(mem_ctx, sizeof(uint32) * r.num_entries2); + *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2); if (!*rids) { DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n")); return NT_STATUS_NO_MEMORY; } - *dom_users = (char**)talloc(mem_ctx, sizeof(char*) * r.num_entries2); + *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2); if (!*dom_users) { DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n")); return NT_STATUS_NO_MEMORY; @@ -931,8 +931,7 @@ NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (*num_dom_groups == 0) goto done; - if (!((*dom_groups) = (struct acct_info *) - talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) { + if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) { result = NT_STATUS_NO_MEMORY; goto done; } @@ -1014,8 +1013,7 @@ NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (*num_dom_aliases == 0) goto done; - if (!((*dom_aliases) = (struct acct_info *) - talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_aliases))) { + if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) { result = NT_STATUS_NO_MEMORY; goto done; } @@ -1096,7 +1094,7 @@ NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx, goto done; } - if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) { + if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) { result = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1654,8 +1652,8 @@ NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx, } *num_names = r.num_names1; - *names = talloc(mem_ctx, sizeof(char *) * r.num_names1); - *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1); + *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1); + *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1); for (i = 0; i < r.num_names1; i++) { fstring tmp; @@ -1724,8 +1722,8 @@ NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx, } *num_rids = r.num_rids1; - *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1); - *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1); + *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1); + *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1); for (i = 0; i < r.num_rids1; i++) { (*rids)[i] = r.rids[i]; diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index dc693eb02c..5030a97c00 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -55,7 +55,7 @@ static void decode_printer_info_0(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PRINTER_INFO_0 *inf; - inf=(PRINTER_INFO_0 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_0)); + inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned); memset(inf, 0, returned*sizeof(PRINTER_INFO_0)); prs_set_offset(&buffer->prs,0); @@ -75,7 +75,7 @@ static void decode_printer_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PRINTER_INFO_1 *inf; - inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1)); + inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned); memset(inf, 0, returned*sizeof(PRINTER_INFO_1)); prs_set_offset(&buffer->prs,0); @@ -95,7 +95,7 @@ static void decode_printer_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PRINTER_INFO_2 *inf; - inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2)); + inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned); memset(inf, 0, returned*sizeof(PRINTER_INFO_2)); prs_set_offset(&buffer->prs,0); @@ -117,7 +117,7 @@ static void decode_printer_info_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PRINTER_INFO_3 *inf; - inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3)); + inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned); memset(inf, 0, returned*sizeof(PRINTER_INFO_3)); prs_set_offset(&buffer->prs,0); @@ -138,7 +138,7 @@ static void decode_printer_info_7(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PRINTER_INFO_7 *inf; - inf=(PRINTER_INFO_7 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_7)); + inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned); memset(inf, 0, returned*sizeof(PRINTER_INFO_7)); prs_set_offset(&buffer->prs,0); @@ -159,7 +159,7 @@ static void decode_port_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PORT_INFO_1 *inf; - inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1)); + inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned); memset(inf, 0, returned*sizeof(PORT_INFO_1)); prs_set_offset(&buffer->prs, 0); @@ -179,7 +179,7 @@ static void decode_port_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; PORT_INFO_2 *inf; - inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2)); + inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned); memset(inf, 0, returned*sizeof(PORT_INFO_2)); prs_set_offset(&buffer->prs, 0); @@ -199,7 +199,7 @@ static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; DRIVER_INFO_1 *inf; - inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1)); + inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned); memset(inf, 0, returned*sizeof(DRIVER_INFO_1)); prs_set_offset(&buffer->prs,0); @@ -219,7 +219,7 @@ static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; DRIVER_INFO_2 *inf; - inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2)); + inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned); memset(inf, 0, returned*sizeof(DRIVER_INFO_2)); prs_set_offset(&buffer->prs,0); @@ -239,7 +239,7 @@ static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 i; DRIVER_INFO_3 *inf; - inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3)); + inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned); memset(inf, 0, returned*sizeof(DRIVER_INFO_3)); prs_set_offset(&buffer->prs,0); @@ -259,7 +259,7 @@ static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, { DRIVER_DIRECTORY_1 *inf; - inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1)); + inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1); memset(inf, 0, sizeof(DRIVER_DIRECTORY_1)); prs_set_offset(&buffer->prs, 0); @@ -1499,7 +1499,7 @@ static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, { int i; - *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1)); + *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms); prs_set_offset(&buffer->prs,0); for (i = 0; i < num_forms; i++) @@ -1581,7 +1581,7 @@ static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, { uint32 i; - *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1)); + *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs); prs_set_offset(&buffer->prs,0); for (i = 0; i < num_jobs; i++) @@ -1593,7 +1593,7 @@ static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, { uint32 i; - *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2)); + *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs); prs_set_offset(&buffer->prs,0); for (i = 0; i < num_jobs; i++) @@ -2016,7 +2016,7 @@ WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Return output parameters */ - value->data_p = talloc_memdup(mem_ctx, r.data, r.needed); + value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed); value->type = r.type; value->size = r.size; @@ -2071,7 +2071,7 @@ WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Return output parameters */ - value->data_p = talloc_memdup(mem_ctx, r.data, r.needed); + value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed); value->type = r.type; value->size = r.needed; @@ -2226,7 +2226,7 @@ WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (value) { rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1, STR_TERMINATE); - value->data_p = talloc_memdup(mem_ctx, r.data, r.realdatasize); + value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.realdatasize); value->type = r.type; value->size = r.realdatasize; } @@ -2483,7 +2483,7 @@ WERROR cli_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Copy results */ if (keylist) { - *keylist = (uint16 *)malloc(r.keys.buf_len * 2); + *keylist = SMB_MALLOC_ARRAY(uint16, r.keys.buf_len); memcpy(*keylist, r.keys.buffer, r.keys.buf_len * 2); if (len) *len = r.keys.buf_len * 2; diff --git a/source3/rpc_client/cli_srvsvc.c b/source3/rpc_client/cli_srvsvc.c index da4721c2c7..3385fbe463 100644 --- a/source3/rpc_client/cli_srvsvc.c +++ b/source3/rpc_client/cli_srvsvc.c @@ -120,8 +120,7 @@ WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, switch(info_level) { case 1: - ctr->share.info1 = (SRV_SHARE_INFO_1 *)talloc( - mem_ctx, sizeof(SRV_SHARE_INFO_1) * ctr->num_entries); + ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, ctr->num_entries); memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1)); @@ -148,8 +147,7 @@ WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, break; case 2: - ctr->share.info2 = (SRV_SHARE_INFO_2 *)talloc( - mem_ctx, sizeof(SRV_SHARE_INFO_2) * ctr->num_entries); + ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, ctr->num_entries); memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2)); @@ -183,8 +181,7 @@ WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, break; /* adding info-level 502 here */ case 502: - ctr->share.info502 = (SRV_SHARE_INFO_502 *)talloc( - mem_ctx, sizeof(SRV_SHARE_INFO_502) * ctr->num_entries); + ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, ctr->num_entries); memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502)); @@ -492,8 +489,7 @@ WERROR cli_srvsvc_net_file_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, switch(file_level) { case 3: - ctr->file.info3 = (SRV_FILE_INFO_3 *)talloc( - mem_ctx, sizeof(SRV_FILE_INFO_3) * ctr->num_entries); + ctr->file.info3 = TALLOC_ARRAY(mem_ctx, SRV_FILE_INFO_3, ctr->num_entries); memset(ctr->file.info3, 0, sizeof(SRV_FILE_INFO_3) * ctr->num_entries); |