[Samba] continuous access to printer causes high memory usage

Jeremy Allison jra at samba.org
Tue Jul 25 21:24:27 GMT 2006


On Tue, Jul 25, 2006 at 05:54:47PM +0200, Roel van Meer wrote:
> Martin Zielinski writes:
> 
> >and http://lists.samba.org/archive/samba/2004-November/096492.html
> >The symptoms are the same as you described.
> 
> This seems to be exactly what is biting us. I've tried to get a 
> configuration on the client that would not result in the spooler to go into 
> a loop, but no success so far.
> 
> As an afterthought, why should a repeated access from a spooler result in 
> unlimited memory consumption of the smbd process? It seems odd.
> 
> The output of 'smbcontrol <pid> pool-usage' on the memory-using smbd 
> processes shows that thare are many references to a structure named 
> NT_PRINTER_INFO_LEVEL (many thousands, increasing with about 230 every 
> minute) that keep the memory allocated. This causes the used virtual memory 
> to increase with about 4 MiB per minute.
> 
> Is this something that is in fact correct behaviour but is leading to too 
> much memory consumption because of the amount of rpc calls?
> 
> As there are more people who seem to have this problem I've opened a 
> bugzilla report: https://bugzilla.samba.org/show_bug.cgi?id=3962

Please try this patch I've just committed (and attached to
the 3962 bug). I think it may fix the problem.

Jeremy.
-------------- next part --------------
Index: rpc_server/srv_spoolss_nt.c
===================================================================
--- rpc_server/srv_spoolss_nt.c	(revision 17233)
+++ rpc_server/srv_spoolss_nt.c	(working copy)
@@ -441,7 +441,7 @@
 	const char *servername;
 	fstring sname;
 	BOOL found=False;
-	NT_PRINTER_INFO_LEVEL *printer;
+	NT_PRINTER_INFO_LEVEL *printer = NULL;
 	WERROR result;
 	
 	DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename)));
@@ -532,6 +532,7 @@
 		printername++;
 		
 		if ( strequal(printername, aprinter) ) {
+			free_a_printer( &printer, 2);
 			found = True;
 			break;
 		}
@@ -541,6 +542,8 @@
 		free_a_printer( &printer, 2);
 	}
 
+	free_a_printer( &printer, 2);
+
 	if ( !found ) {
 		DEBUGADD(4,("Printer not found\n"));
 		return False;
@@ -3551,6 +3554,7 @@
 
 		if((info->data=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
 			DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
+			free_a_printer(&printer, 2);
 			return False;
 		}
 
@@ -4181,6 +4185,7 @@
 	*pp_printer = NULL;
 	if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) {
 		DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
+		free_a_printer(&ntprinter, 2);
 		return False;
 	}
 
@@ -4983,8 +4988,10 @@
 	if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
 		return WERR_INVALID_PRINTER_NAME;
 
-	if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version)))
+	if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
+		free_a_printer(&printer, 2);
 		return WERR_UNKNOWN_PRINTER_DRIVER;
+	}
 
 	fill_printer_driver_info_1(info, driver, servername, architecture);
 
@@ -5043,8 +5050,10 @@
 	if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
 		return WERR_INVALID_PRINTER_NAME;
 
-	if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version)))
+	if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
+		free_a_printer(&printer, 2);
 		return WERR_UNKNOWN_PRINTER_DRIVER;
+	}
 
 	fill_printer_driver_info_2(info, driver, servername);
 
@@ -6611,22 +6620,24 @@
 
 	if (*returned == 0) {
 		SAFE_FREE(queue);
+		free_a_printer(&ntprinter, 2);
 		return WERR_OK;
 	}
 
 	switch (level) {
 	case 1:
 		wret = enumjobs_level1(queue, snum, ntprinter, buffer, offered, needed, returned);
-		return wret;
+		break;
 	case 2:
 		wret = enumjobs_level2(queue, snum, ntprinter, buffer, offered, needed, returned);
-		return wret;
+		break;
 	default:
-		SAFE_FREE(queue);
 		*returned=0;
 		wret = WERR_UNKNOWN_LEVEL;
+		break;
 	}
 	
+	SAFE_FREE(queue);
 	free_a_printer( &ntprinter, 2 );
 	return wret;
 }


More information about the samba mailing list