printing: don't leak cache_path onto talloc tos
[vlendec/samba-autobuild/.git] / source3 / printing / load.c
index 4f1bb88a99636312f381d7a00c0d50ca3d769106..238998d920d7d2b943b01734d4ef78c1e4394cf4 100644 (file)
@@ -19,7 +19,8 @@
 
 #include "includes.h"
 #include "printing/pcap.h"
-
+#include "printing/load.h"
+#include "lib/param/loadparm.h"
 
 /***************************************************************************
 auto-load some homes and printer services
@@ -30,6 +31,7 @@ static void add_auto_printers(void)
        int pnum = lp_servicenumber(PRINTERS_NAME);
        char *str;
        char *saveptr;
+       char *auto_serv = NULL;
 
        if (pnum < 0)
                if (process_registry_service(PRINTERS_NAME))
@@ -38,8 +40,12 @@ static void add_auto_printers(void)
        if (pnum < 0)
                return;
 
-       if ((str = SMB_STRDUP(lp_auto_services())) == NULL)
+       auto_serv = lp_auto_services(talloc_tos());
+       str = SMB_STRDUP(auto_serv);
+       TALLOC_FREE(auto_serv);
+       if (str == NULL) {
                return;
+       }
 
        for (p = strtok_r(str, LIST_SEP, &saveptr); p;
             p = strtok_r(NULL, LIST_SEP, &saveptr)) {
@@ -54,18 +60,16 @@ static void add_auto_printers(void)
 }
 
 /***************************************************************************
-load automatic printer services
+load automatic printer services from pre-populated pcap cache
 ***************************************************************************/
 void load_printers(struct tevent_context *ev,
                   struct messaging_context *msg_ctx)
 {
-       if (!pcap_cache_loaded()) {
-               pcap_cache_reload(ev, msg_ctx);
-       }
+       SMB_ASSERT(pcap_cache_loaded(NULL));
 
        add_auto_printers();
 
        /* load all printcap printers */
        if (lp_load_printers() && lp_servicenumber(PRINTERS_NAME) >= 0)
-               pcap_printer_fn(lp_add_one_printer, NULL);
+               pcap_printer_read_fn(lp_add_one_printer, NULL);
 }