]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix free of argv values in cupsdContinueJob.
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Fri, 8 Nov 2013 15:16:53 +0000 (15:16 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Fri, 8 Nov 2013 15:16:53 +0000 (15:16 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11416 a1ca3aef-8c08-0410-bb20-df032aa958be

scheduler/job.c
scheduler/printers.c

index f47d111de82d99b1a77d42d73ef8abcdb5e41fdc..cc0f11b1c4a9a2d9a2fb716220569573bdb82898 100644 (file)
@@ -491,6 +491,7 @@ cupsdContinueJob(cupsd_job_t *job)  /* I - Job */
                                        /* Pipes used between filters */
   int                  envc;           /* Number of environment variables */
   struct stat          fileinfo;       /* Job file information */
                                        /* Pipes used between filters */
   int                  envc;           /* Number of environment variables */
   struct stat          fileinfo;       /* Job file information */
+  int                  argc;           /* Number of arguments */
   char                 **argv = NULL,  /* Filter command-line arguments */
                        filename[1024], /* Job filename */
                        command[1024],  /* Full path to command */
   char                 **argv = NULL,  /* Filter command-line arguments */
                        filename[1024], /* Job filename */
                        command[1024],  /* Full path to command */
@@ -841,11 +842,11 @@ cupsdContinueJob(cupsd_job_t *job)        /* I - Job */
   */
 
   if (job->printer->remote)
   */
 
   if (job->printer->remote)
-    argv = calloc(7 + job->num_files, sizeof(char *));
+    argc = 6 + job->num_files;
   else
   else
-    argv = calloc(8, sizeof(char *));
+    argc = 7;
 
 
-  if (!argv)
+  if ((argv = calloc(argc + 1, sizeof(char *))) == NULL)
   {
     cupsdLogMessage(CUPSD_LOG_DEBUG, "Unable to allocate argument array - %s",
                     strerror(errno));
   {
     cupsdLogMessage(CUPSD_LOG_DEBUG, "Unable to allocate argument array - %s",
                     strerror(errno));
@@ -1177,8 +1178,13 @@ cupsdContinueJob(cupsd_job_t *job)       /* I - Job */
     cupsdLogJob(job, CUPSD_LOG_INFO, "Started filter %s (PID %d)", command,
                 pid);
 
     cupsdLogJob(job, CUPSD_LOG_INFO, "Started filter %s (PID %d)", command,
                 pid);
 
-    argv[6] = NULL;
-    slot    = !slot;
+    if (argv[6])
+    {
+      free(argv[6]);
+      argv[6] = NULL;
+    }
+
+    slot = !slot;
   }
 
   cupsArrayDelete(filters);
   }
 
   cupsArrayDelete(filters);
@@ -1262,8 +1268,9 @@ cupsdContinueJob(cupsd_job_t *job)        /* I - Job */
 
   cupsdClosePipe(filterfds[slot]);
 
 
   cupsdClosePipe(filterfds[slot]);
 
-  for (i = 0; i < job->num_files; i ++)
-    free(argv[i + 6]);
+  for (i = 6; i < argc; i ++)
+    if (argv[i])
+      free(argv[i]);
 
   free(argv);
 
 
   free(argv);
 
@@ -1296,13 +1303,9 @@ cupsdContinueJob(cupsd_job_t *job)       /* I - Job */
 
   if (argv)
   {
 
   if (argv)
   {
-    if (job->printer->remote && job->num_files > 1)
-    {
-      for (i = 0; i < job->num_files; i ++)
-       free(argv[i + 6]);
-    }
-
-    free(argv);
+    for (i = 6; i < argc; i ++)
+      if (argv[i])
+       free(argv[i]);
   }
 
   if (printer_state_reasons)
   }
 
   if (printer_state_reasons)
index 48e7e0e4e29265f584dac1bb8d55b68adda23624..3c709c801622c2581342d7cdac4179a3f390d530 100644 (file)
@@ -1910,6 +1910,7 @@ cupsdSetPrinterAttr(
 
     if (!attr)
     {
 
     if (!attr)
     {
+      free(temp);
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Unable to allocate memory for printer attribute "
                      "(%d values)", count);
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Unable to allocate memory for printer attribute "
                      "(%d values)", count);
@@ -1960,6 +1961,7 @@ cupsdSetPrinterAttr(
 
     if (!attr)
     {
 
     if (!attr)
     {
+      free(temp);
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Unable to allocate memory for printer attribute "
                      "(%d values)", count);
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Unable to allocate memory for printer attribute "
                      "(%d values)", count);