s3-printing: fix memory leak in print_cups.c
authorDavid Disseldorp <ddiss@suse.de>
Wed, 9 Mar 2011 14:18:22 +0000 (15:18 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 16 Mar 2011 15:37:58 +0000 (16:37 +0100)
As found by valgrind, tmp_pcap_cache is not freed following printer list
tdb update.

Signed-off-by: Andreas Schneider <asn@samba.org>
Autobuild-User: Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date: Wed Mar 16 16:37:58 CET 2011 on sn-devel-104

source3/printing/print_cups.c

index b151511b21b2d7d190e5214a6622df04c8bf97da..e3b08b7d2e16172ca0eaa0db2903d75edbb3aae9 100644 (file)
@@ -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);