[PATCH 4/4] s3-printing: fix memory leak in print_cups.c

David Disseldorp ddiss at suse.de
Tue Mar 15 07:06:25 MDT 2011


As found by valgrind, tmp_pcap_cache is not freed following printer list
tdb update.
---
 source3/printing/print_cups.c |   25 +++++++++----------------
 1 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index 6325ea1..bed695a 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -481,28 +481,21 @@ static void cups_async_callback(struct event_context *event_ctx,
 						 pcap_data.printers[i].info);
 		if (!ret_ok) {
 			DEBUG(0, ("failed to add to tmp pcap cache\n"));
-			break;
+			goto err_out;
 		}
 	}
 
+	/* replace the system-wide pcap cache with a (possibly empty) new one */
+	ret_ok = pcap_cache_replace(tmp_pcap_cache);
 	if (!ret_ok) {
-		DEBUG(0, ("failed to read a new printer list\n"));
-		pcap_cache_destroy_specific(&tmp_pcap_cache);
-	} else {
-		/*
-		 * replace the system-wide pcap cache with a (possibly empty)
-		 * new one.
-		 */
-		ret_ok = pcap_cache_replace(tmp_pcap_cache);
-		if (!ret_ok) {
-			DEBUG(0, ("failed to replace pcap cache\n"));
-		} else if (cb_args->post_cache_fill_fn != NULL) {
-			/* Caller requested post cache fill callback */
-			cb_args->post_cache_fill_fn(cb_args->event_ctx,
-						    cb_args->msg_ctx);
-		}
+		DEBUG(0, ("failed to replace pcap cache\n"));
+	} else if (cb_args->post_cache_fill_fn != NULL) {
+		/* Caller requested post cache fill callback */
+		cb_args->post_cache_fill_fn(cb_args->event_ctx,
+					    cb_args->msg_ctx);
 	}
 err_out:
+	pcap_cache_destroy_specific(&tmp_pcap_cache);
 	TALLOC_FREE(frame);
 	close(cb_args->pipe_fd);
 	TALLOC_FREE(cb_args);
-- 
1.7.3.4



More information about the samba-technical mailing list