summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-12-07 18:25:53 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:53:32 -0500
commitacf9d61421faa6c0055d57fdee7db300dc5431aa (patch)
tree5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/printing
parent3bd3be97dc8a581c0502410453091c195e322766 (diff)
downloadsamba-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/printing')
-rw-r--r--source3/printing/load.c2
-rw-r--r--source3/printing/notify.c16
-rw-r--r--source3/printing/nt_printing.c50
-rw-r--r--source3/printing/print_cups.c2
-rw-r--r--source3/printing/print_generic.c2
-rw-r--r--source3/printing/printing.c8
-rw-r--r--source3/printing/printing_db.c2
7 files changed, 43 insertions, 39 deletions
diff --git a/source3/printing/load.c b/source3/printing/load.c
index cd90cbb6f3..59306aa104 100644
--- a/source3/printing/load.c
+++ b/source3/printing/load.c
@@ -40,7 +40,7 @@ static void add_auto_printers(void)
{
const char *p;
int printers;
- char *str = strdup(lp_auto_services());
+ char *str = SMB_STRDUP(lp_auto_services());
if (!str) return;
diff --git a/source3/printing/notify.c b/source3/printing/notify.c
index 77326bee3e..0071d3d8c0 100644
--- a/source3/printing/notify.c
+++ b/source3/printing/notify.c
@@ -99,7 +99,7 @@ again:
msg->len, msg->notify.data);
if (buflen != len) {
- buf = talloc_realloc(send_ctx, buf, len);
+ buf = TALLOC_REALLOC(send_ctx, buf, len);
if (!buf)
return False;
buflen = len;
@@ -140,7 +140,7 @@ static void print_notify_send_messages_to_printer(const char *printer, unsigned
}
offset += 4; /* For count. */
- buf = talloc(send_ctx, offset);
+ buf = TALLOC(send_ctx, offset);
if (!buf) {
DEBUG(0,("print_notify_send_messages: Out of memory\n"));
talloc_destroy_pool(send_ctx);
@@ -218,7 +218,7 @@ static BOOL copy_notify2_msg( SPOOLSS_NOTIFY_MSG *to, SPOOLSS_NOTIFY_MSG *from )
memcpy( to, from, sizeof(SPOOLSS_NOTIFY_MSG) );
if ( from->len ) {
- to->notify.data = talloc_memdup(send_ctx, from->notify.data, from->len );
+ to->notify.data = TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );
if ( !to->notify.data ) {
DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len ));
return False;
@@ -267,7 +267,7 @@ static void send_spoolss_notify2_msg(SPOOLSS_NOTIFY_MSG *msg)
/* Store the message on the pending queue. */
- pnqueue = talloc(send_ctx, sizeof(*pnqueue));
+ pnqueue = TALLOC_P(send_ctx, struct notify_queue);
if (!pnqueue) {
DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n"));
return;
@@ -275,7 +275,7 @@ static void send_spoolss_notify2_msg(SPOOLSS_NOTIFY_MSG *msg)
/* allocate a new msg structure and copy the fields */
- if ( !(pnqueue->msg = (SPOOLSS_NOTIFY_MSG*)talloc(send_ctx, sizeof(SPOOLSS_NOTIFY_MSG))) ) {
+ if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n",
(unsigned long)sizeof(SPOOLSS_NOTIFY_MSG)));
return;
@@ -309,7 +309,7 @@ static void send_notify_field_values(const char *sharename, uint32 type,
if (!create_send_ctx())
return;
- msg = (struct spoolss_notify_msg *)talloc(send_ctx, sizeof(struct spoolss_notify_msg));
+ msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
if (!msg)
return;
@@ -338,7 +338,7 @@ static void send_notify_field_buffer(const char *sharename, uint32 type,
if (!create_send_ctx())
return;
- msg = (struct spoolss_notify_msg *)talloc(send_ctx, sizeof(struct spoolss_notify_msg));
+ msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
if (!msg)
return;
@@ -535,7 +535,7 @@ BOOL print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx, size_t
num_pids = data.dsize / 8;
- if ((pid_list = (pid_t *)talloc(mem_ctx, sizeof(pid_t) * num_pids)) == NULL) {
+ if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
ret = False;
goto done;
}
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index 2dc565c79c..b17ddb51ca 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -531,7 +531,7 @@ int get_ntforms(nt_forms_struct **list)
if (ret != dbuf.dsize)
continue;
- tl = Realloc(*list, sizeof(nt_forms_struct)*(n+1));
+ tl = SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1);
if (!tl) {
DEBUG(0,("get_ntforms: Realloc fail.\n"));
return 0;
@@ -601,7 +601,7 @@ BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count)
}
if (update==False) {
- if((tl=Realloc(*list, (n+1)*sizeof(nt_forms_struct))) == NULL) {
+ if((tl=SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1)) == NULL) {
DEBUG(0,("add_a_form: failed to enlarge forms list!\n"));
return False;
}
@@ -710,7 +710,7 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
if (strncmp(kbuf.dptr, key, strlen(key)) != 0)
continue;
- if((fl = Realloc(*list, sizeof(fstring)*(total+1))) == NULL) {
+ if((fl = SMB_REALLOC_ARRAY(*list, fstring, total+1)) == NULL) {
DEBUG(0,("get_ntdrivers: failed to enlarge list!\n"));
return -1;
}
@@ -766,7 +766,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
char *buf = NULL;
ssize_t byte_count;
- if ((buf=malloc(PE_HEADER_SIZE)) == NULL) {
+ if ((buf=SMB_MALLOC(PE_HEADER_SIZE)) == NULL) {
DEBUG(0,("get_file_version: PE file [%s] PE Header malloc failed bytes = %d\n",
fname, PE_HEADER_SIZE));
goto error_exit;
@@ -822,7 +822,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
goto error_exit;
SAFE_FREE(buf);
- if ((buf=malloc(section_table_bytes)) == NULL) {
+ if ((buf=SMB_MALLOC(section_table_bytes)) == NULL) {
DEBUG(0,("get_file_version: PE file [%s] section table malloc failed bytes = %d\n",
fname, section_table_bytes));
goto error_exit;
@@ -846,7 +846,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
goto error_exit;
SAFE_FREE(buf);
- if ((buf=malloc(section_bytes)) == NULL) {
+ if ((buf=SMB_MALLOC(section_bytes)) == NULL) {
DEBUG(0,("get_file_version: PE file [%s] version malloc failed bytes = %d\n",
fname, section_bytes));
goto error_exit;
@@ -906,7 +906,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
/* Allocate a bit more space to speed up things */
SAFE_FREE(buf);
- if ((buf=malloc(VS_NE_BUF_SIZE)) == NULL) {
+ if ((buf=SMB_MALLOC(VS_NE_BUF_SIZE)) == NULL) {
DEBUG(0,("get_file_version: NE file [%s] malloc failed bytes = %d\n",
fname, PE_HEADER_SIZE));
goto error_exit;
@@ -1728,7 +1728,7 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
if (len != buflen) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0,("add_a_printer_driver_3: failed to enlarge buffer\n!"));
ret = -1;
@@ -1793,7 +1793,7 @@ static WERROR get_a_printer_driver_3_default(NT_PRINTER_DRIVER_INFO_LEVEL_3 **in
fstrcpy(info.configfile, "");
fstrcpy(info.helpfile, "");
- if ((info.dependentfiles=(fstring *)malloc(2*sizeof(fstring))) == NULL)
+ if ((info.dependentfiles= SMB_MALLOC_ARRAY(fstring, 2)) == NULL)
return WERR_NOMEM;
memset(info.dependentfiles, '\0', 2*sizeof(fstring));
@@ -1850,8 +1850,7 @@ static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
while (len < dbuf.dsize) {
fstring *tddfs;
- tddfs = (fstring *)Realloc(driver.dependentfiles,
- sizeof(fstring)*(i+2));
+ tddfs = SMB_REALLOC_ARRAY(driver.dependentfiles, fstring, i+2);
if (tddfs == NULL) {
DEBUG(0,("get_a_printer_driver_3: failed to enlarge buffer!\n"));
break;
@@ -2133,7 +2132,7 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info)
if (buflen != len) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0,("update_a_printer_2: failed to enlarge buffer!\n"));
ret = WERR_NOMEM;
@@ -2175,7 +2174,7 @@ NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename)
{
char adevice[MAXDEVICENAME];
- NT_DEVICEMODE *nt_devmode = (NT_DEVICEMODE *)malloc(sizeof(NT_DEVICEMODE));
+ NT_DEVICEMODE *nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE);
if (nt_devmode == NULL) {
DEBUG(0,("construct_nt_devicemode: malloc fail.\n"));
@@ -2395,7 +2394,7 @@ static int add_new_printer_key( NT_PRINTER_DATA *data, const char *name )
/* allocate another slot in the NT_PRINTER_KEY array */
- d = Realloc( data->keys, sizeof(NT_PRINTER_KEY)*(data->num_keys+1) );
+ d = SMB_REALLOC_ARRAY( data->keys, NT_PRINTER_KEY, data->num_keys+1);
if ( d )
data->keys = d;
@@ -2404,7 +2403,7 @@ static int add_new_printer_key( NT_PRINTER_DATA *data, const char *name )
/* initialze new key */
data->num_keys++;
- data->keys[key_index].name = strdup( name );
+ data->keys[key_index].name = SMB_STRDUP( name );
ZERO_STRUCTP( &data->keys[key_index].values );
@@ -2487,7 +2486,7 @@ uint32 get_printer_subkeys( NT_PRINTER_DATA *data, const char* key, fstring **su
/* found a match, so allocate space and copy the name */
- if ( !(ptr = Realloc( subkeys_ptr, (num_subkeys+2)*sizeof(fstring))) ) {
+ if ( !(ptr = SMB_REALLOC_ARRAY( subkeys_ptr, fstring, num_subkeys+2)) ) {
DEBUG(0,("get_printer_subkeys: Realloc failed for [%d] entries!\n",
num_subkeys+1));
SAFE_FREE( subkeys );
@@ -2550,9 +2549,14 @@ static void map_single_multi_sz_into_ctr(REGVAL_CTR *ctr, const char *val_name,
/* a multi-sz has to have a null string terminator, i.e., the last
string must be followed by two nulls */
- str_size = (strlen(multi_sz) + 2) * sizeof(smb_ucs2_t);
- conv_strs = calloc(str_size, 1);
+ str_size = strlen(multi_sz) + 2;
+ conv_strs = SMB_CALLOC_ARRAY(smb_ucs2_t, str_size);
+ if (!conv_strs) {
+ return;
+ }
+ /* Change to byte units. */
+ str_size *= sizeof(smb_ucs2_t);
push_ucs2(NULL, conv_strs, multi_sz, str_size,
STR_TERMINATE | STR_NOALIGN);
@@ -3773,7 +3777,7 @@ static uint32 update_driver_init_2(NT_PRINTER_INFO_LEVEL_2 *info)
if (buflen < len) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0, ("update_driver_init_2: failed to enlarge buffer!\n"));
ret = -1;
@@ -3897,7 +3901,7 @@ static WERROR save_driver_init_2(NT_PRINTER_INFO_LEVEL *printer, uint8 *data, ui
if ((ctx = talloc_init("save_driver_init_2")) == NULL)
return WERR_NOMEM;
- if ((nt_devmode = (NT_DEVICEMODE*)malloc(sizeof(NT_DEVICEMODE))) == NULL) {
+ if ((nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE)) == NULL) {
status = WERR_NOMEM;
goto done;
}
@@ -4014,7 +4018,7 @@ NT_PRINTER_INFO_LEVEL_2* dup_printer_2( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2
if ( !printer )
return NULL;
- if ( !(copy = (NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2))) )
+ if ( !(copy = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2)) )
return NULL;
memcpy( copy, printer, sizeof(NT_PRINTER_INFO_LEVEL_2) );
@@ -4062,7 +4066,7 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print
switch (level) {
case 2:
- if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
+ if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
DEBUG(0,("get_a_printer: malloc fail.\n"));
return WERR_NOMEM;
}
@@ -4123,7 +4127,7 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print
/* save a copy in cache */
if ( print_hnd && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER)) {
if ( !print_hnd->printer_info )
- print_hnd->printer_info = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL));
+ print_hnd->printer_info = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL);
if ( print_hnd->printer_info ) {
/* make sure to use the handle's talloc ctx here since
diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index 2a59e2c5d3..5cc36d6e17 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -909,7 +909,7 @@ cups_queue_get(const char *printer_name,
{
qalloc += 16;
- temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
+ temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
if (temp == NULL)
{
diff --git a/source3/printing/print_generic.c b/source3/printing/print_generic.c
index d6074704b3..256654179e 100644
--- a/source3/printing/print_generic.c
+++ b/source3/printing/print_generic.c
@@ -194,7 +194,7 @@ static int generic_queue_get(const char *printer_name,
qcount = 0;
ZERO_STRUCTP(status);
if (numlines)
- queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
+ queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
if (queue) {
memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 9d9ebba950..5c8790e34b 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -536,7 +536,7 @@ static BOOL pjob_store(const char* sharename, uint32 jobid, struct printjob *pjo
if (buflen != len) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
goto done;
@@ -934,7 +934,7 @@ static void store_queue_struct(struct tdb_print_db *pdb, struct traverse_struct
queue[i].fs_file);
}
- if ((data.dptr = malloc(data.dsize)) == NULL)
+ if ((data.dptr = SMB_MALLOC(data.dsize)) == NULL)
return;
len = 0;
@@ -1423,7 +1423,7 @@ BOOL print_notify_register_pid(int snum)
if (i == data.dsize) {
/* We weren't in the list. Realloc. */
- data.dptr = Realloc(data.dptr, data.dsize + 8);
+ data.dptr = SMB_REALLOC(data.dptr, data.dsize + 8);
if (!data.dptr) {
DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n",
printername));
@@ -2379,7 +2379,7 @@ static BOOL get_stored_queue_info(struct tdb_print_db *pdb, int snum, int *pcoun
if (qcount == 0 && extra_count == 0)
goto out;
- if ((queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(qcount + extra_count))) == NULL)
+ if ((queue = SMB_MALLOC_ARRAY(print_queue_struct, qcount + extra_count)) == NULL)
goto out;
/* Retrieve the linearised queue data. */
diff --git a/source3/printing/printing_db.c b/source3/printing/printing_db.c
index d45ad1cff7..b9b4b3c6b0 100644
--- a/source3/printing/printing_db.c
+++ b/source3/printing/printing_db.c
@@ -80,7 +80,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
if (!p) {
/* Create one. */
- p = (struct tdb_print_db *)malloc(sizeof(struct tdb_print_db));
+ p = SMB_MALLOC_P(struct tdb_print_db);
if (!p) {
DEBUG(0,("get_print_db: malloc fail !\n"));
return NULL;