From fe4d6cd3bb52f4a28b91f90c3e64e782e2f2f08e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2001 04:00:45 +0000 Subject: Fix memory leaks introduced in restructure. Jeremy. (This used to be commit a355e11201e4dcb495b65b86e79de40d94c52a5b) --- source3/rpc_server/srv_spoolss_nt.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c5a15ed37e..341117f346 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1113,7 +1113,8 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ -static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) + +static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; @@ -1121,7 +1122,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "BeepEnabled")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x01); *needed = 0x4; @@ -1130,7 +1131,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "EventLog")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x1B); *needed = 0x4; @@ -1139,7 +1140,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "NetPopup")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x01); *needed = 0x4; @@ -1148,7 +1149,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "MajorVersion")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x02); *needed = 0x4; @@ -1159,9 +1160,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d pstring string="You are using a Samba server"; *type = 0x1; *needed = 2*(strlen(string)+1); - if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; - memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; - memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iin_size)?in_size:len *sizeof(uint8)); } else { @@ -1278,7 +1276,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(4,("_spoolss_getprinterdata\n")); if (!OPEN_HANDLE(Printer)) { - if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) + if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; @@ -1287,9 +1285,9 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO unistr2_to_ascii(value, valuename, sizeof(value)-1); if (handle_is_printserver(handle)) - found=getprinterdata_printer_server(value, type, data, needed, *out_size); + found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); else - found= getprinterdata_printer(handle, value, type, data, needed, *out_size); + found= getprinterdata_printer(p->mem_ctx, handle, value, type, data, needed, *out_size); if (found==False) { DEBUG(5, ("value not found, allocating %d\n", *out_size)); -- cgit