s3-printing: pass a talloc ctx to unpack_pjob
authorDavid Disseldorp <ddiss@samba.org>
Wed, 8 Feb 2012 16:57:02 +0000 (17:57 +0100)
committerDavid Disseldorp <ddiss@samba.org>
Mon, 25 Jun 2012 12:42:16 +0000 (14:42 +0200)
Rather than allocating the devicemode on a null context.

source3/printing/printing.c
source3/rpc_server/spoolss/srv_spoolss_nt.c

index 886077fb174c0bb282ec57e8d27ac1b93b07a2a2..69281846dfa09ed918d6e76a96970c1351ecaf98 100644 (file)
@@ -380,8 +380,8 @@ done:
  unpack a pjob from a tdb buffer
 ***********************************************************************/
 
-/* FIXME talloc ctx */
-static int unpack_pjob(uint8 *buf, int buflen, struct printjob *pjob)
+static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
+                      struct printjob *pjob)
 {
        int     len = 0;
        int     used;
@@ -413,7 +413,7 @@ static int unpack_pjob(uint8 *buf, int buflen, struct printjob *pjob)
                return -1;
        }
 
-        used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
+        used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode);
         if (used == -1) {
                return -1;
         }
@@ -469,7 +469,7 @@ static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
                goto err_out;
        }
 
-       if (unpack_pjob(ret.dptr, ret.dsize, pjob) == -1) {
+       if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) {
                DEBUG(10, ("failed to unpack jobid %u.\n", jobid));
                talloc_free(pjob);
                pjob = NULL;
@@ -804,30 +804,32 @@ static bool pjob_store(struct tevent_context *ev,
 
        /* Send notify updates for what has changed */
 
-       if ( ret ) {
+       if (ret) {
                bool changed = false;
                struct printjob old_pjob;
 
-               if ( old_data.dsize )
-               {
-                       if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
-                       {
-                               pjob_store_notify(server_event_context(),
+               if (old_data.dsize) {
+                       TALLOC_CTX *tmp_ctx = talloc_new(ev);
+                       if (tmp_ctx == NULL)
+                               goto done;
+
+                       len = unpack_pjob(tmp_ctx, old_data.dptr,
+                                         old_data.dsize, &old_pjob);
+                       if (len != -1 ) {
+                               pjob_store_notify(ev,
                                                  msg_ctx,
                                                  sharename, jobid, &old_pjob,
                                                  pjob,
                                                  &changed);
-                               talloc_free(old_pjob.devmode);
-
                                if (changed) {
                                        add_to_jobs_changed(pdb, jobid);
                                }
                        }
+                       talloc_free(tmp_ctx);
 
-               }
-               else {
+               } else {
                        /* new job */
-                       pjob_store_notify(server_event_context(), msg_ctx,
+                       pjob_store_notify(ev, msg_ctx,
                                          sharename, jobid, NULL, pjob,
                                          &changed);
                }
@@ -946,6 +948,7 @@ struct traverse_struct {
        struct printif *print_if;
        struct tevent_context *ev;
        struct messaging_context *msg_ctx;
+       TALLOC_CTX *mem_ctx;
 };
 
 /****************************************************************************
@@ -962,7 +965,7 @@ static int traverse_fn_delete(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void
        if (  key.dsize != sizeof(jobid) )
                return 0;
 
-       if (unpack_pjob(data.dptr, data.dsize, &pjob) == -1)
+       if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1)
                return 0;
        talloc_free(pjob.devmode);
        jobid = pjob.jobid;
@@ -1443,7 +1446,6 @@ static void print_queue_update_internal(struct tevent_context *ev,
        }
 
        SAFE_FREE(jcdata.dptr);
-       talloc_free(tmp_ctx);
 
        /* now delete any queued entries that don't appear in the
            system queue */
@@ -1457,6 +1459,7 @@ static void print_queue_update_internal(struct tevent_context *ev,
        tstruct.print_if = current_printif;
        tstruct.ev = ev;
        tstruct.msg_ctx = msg_ctx;
+       tstruct.mem_ctx = tmp_ctx;
 
        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
 
@@ -1464,6 +1467,7 @@ static void print_queue_update_internal(struct tevent_context *ev,
        store_queue_struct(pdb, &tstruct);
 
        SAFE_FREE(tstruct.queue);
+       talloc_free(tmp_ctx);
 
        DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n",
                                sharename, tstruct.total_jobs ));
index 7befe7fd8f2f7ef94d888458dc5ff0b77df970c1..8278ae8390e6b4cbb7f93cfc86aaa29216e4023f 100644 (file)
@@ -9302,7 +9302,7 @@ static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
         *  a failure condition
         */
 
-       devmode = print_job_devmode(lp_const_servicename(snum), jobid);
+       devmode = print_job_devmode(mem_ctx, lp_const_servicename(snum), jobid);
        if (!devmode) {
                result = spoolss_create_default_devmode(mem_ctx,
                                                pinfo2->printername,