Blame SOURCES/cups-browsed-memory-leaks.patch

11fe80
diff --git a/cupsfilters/ppdgenerator.c b/cupsfilters/ppdgenerator.c
11fe80
index 3bc4d8a..44d9313 100644
11fe80
--- a/cupsfilters/ppdgenerator.c
11fe80
+++ b/cupsfilters/ppdgenerator.c
11fe80
@@ -752,12 +752,17 @@ load_opt_strings_catalog(const char *location, cups_array_t *options)
11fe80
 		     2: "..." = "..."
11fe80
 		    10: EOF, save last entry */
11fe80
   int digit;
11fe80
+  int found_in_catalog = 0;
11fe80
 
11fe80
   if (location == NULL || (strncasecmp(location, "http:", 5) &&
11fe80
 			   strncasecmp(location, "https:", 6))) {
11fe80
     if (location == NULL ||
11fe80
 	(stat(location, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))) /* directory? */
11fe80
+    {
11fe80
       filename = _findCUPSMessageCatalog(location);
11fe80
+      if (filename)
11fe80
+        found_in_catalog = 1;
11fe80
+    }
11fe80
     else
11fe80
       filename = location;
11fe80
   } else {
11fe80
@@ -943,6 +948,8 @@ load_opt_strings_catalog(const char *location, cups_array_t *options)
11fe80
     free(opt_name);
11fe80
   if (filename == tmpfile)
11fe80
     unlink(filename);
11fe80
+  if (found_in_catalog)
11fe80
+    free(filename);
11fe80
 }
11fe80
 
11fe80
 
11fe80
@@ -1417,10 +1424,16 @@ ppdCreateFromIPP(char   *buffer,	/* I - Filename buffer */
11fe80
       } else {
11fe80
 	if ((current_res = resolutionArrayNew()) != NULL) {
11fe80
 	  if ((current_def = resolutionNew(lowdpi, lowdpi)) != NULL)
11fe80
+          {
11fe80
 	    cupsArrayAdd(current_res, current_def);
11fe80
+            free_resolution(current_def, NULL);
11fe80
+          }
11fe80
 	  if (hidpi != lowdpi &&
11fe80
 	      (current_def = resolutionNew(hidpi, hidpi)) != NULL)
11fe80
+          {
11fe80
 	    cupsArrayAdd(current_res, current_def);
11fe80
+            free_resolution(current_def, NULL);
11fe80
+          }
11fe80
 	  current_def = NULL;
11fe80
 	  if (cupsArrayCount(current_res) > 0 &&
11fe80
 	      joinResolutionArrays(&common_res, &current_res, &common_def,
11fe80
@@ -1506,7 +1519,10 @@ ppdCreateFromIPP(char   *buffer,	/* I - Filename buffer */
11fe80
   if (common_res == NULL) {
11fe80
     if ((common_res = resolutionArrayNew()) != NULL) {
11fe80
       if ((current_def = resolutionNew(300, 300)) != NULL)
11fe80
+      {
11fe80
 	cupsArrayAdd(common_res, current_def);
11fe80
+        free_resolution(current_def, NULL);
11fe80
+      }
11fe80
       current_def = NULL;
11fe80
     } else
11fe80
       goto bad_ppd;
11fe80
diff --git a/utils/cups-browsed.c b/utils/cups-browsed.c
11fe80
index 54ae2ac..507977c 100644
11fe80
--- a/utils/cups-browsed.c
11fe80
+++ b/utils/cups-browsed.c
11fe80
@@ -2555,7 +2555,7 @@ record_printer_options(const char *printer) {
11fe80
   const char *key;
11fe80
   char buf[65536], *c;
11fe80
   const char *ppdname = NULL;
11fe80
-  ppd_file_t *ppd;
11fe80
+  ppd_file_t *ppd = NULL;
11fe80
   ppd_option_t *ppd_opt;
11fe80
   cups_option_t *option;
11fe80
   int i;
11fe80
@@ -2825,7 +2825,8 @@ on_printer_state_changed (CupsNotifier *object,
11fe80
   char *ptr, buf[1024];
11fe80
   remote_printer_t *p, *q;
11fe80
   http_t *http = NULL;
11fe80
-  ipp_t *request, *response;
11fe80
+  ipp_t *request = NULL;
11fe80
+  ipp_t *response = NULL;
11fe80
   ipp_attribute_t *attr;
11fe80
   const char *pname = NULL;
11fe80
   char *remote_cups_queue;
11fe80
@@ -3107,6 +3108,10 @@ on_printer_state_changed (CupsNotifier *object,
11fe80
 		  break;
11fe80
 		}
11fe80
 	      }
11fe80
+              if (response) {
11fe80
+                ippDelete(response);
11fe80
+                response = NULL;
11fe80
+              }
11fe80
 	      if (pstate == IPP_PRINTER_IDLE && paccept) {
11fe80
 		q->last_printer = i;
11fe80
 		break;
11fe80
@@ -3863,7 +3868,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	debug_printf("Default page size: %s\n",
11fe80
 		     default_page_size);
11fe80
 	p->num_options = cupsAddOption("media-default",
11fe80
-				       strdup(default_page_size),
11fe80
+				       default_page_size,
11fe80
 				       p->num_options, &(p->options));
11fe80
       } else {
11fe80
 	attr = ippFindAttribute(response,
11fe80
@@ -3874,7 +3879,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	  debug_printf("Default page size: %s\n",
11fe80
 		       default_page_size);
11fe80
 	  p->num_options = cupsAddOption("media-default",
11fe80
-					 strdup(default_page_size),
11fe80
+					 default_page_size,
11fe80
 					 p->num_options, &(p->options));
11fe80
 	} else
11fe80
 	  debug_printf("No default page size found!\n");
11fe80
@@ -3889,7 +3894,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	bottom = 1270;
11fe80
       snprintf(buffer, sizeof(buffer), "%d", bottom);
11fe80
       p->num_options = cupsAddOption("media-bottom-margin-default",
11fe80
-				     strdup(buffer),
11fe80
+				     buffer,
11fe80
 				     p->num_options, &(p->options));
11fe80
 
11fe80
       if ((attr = ippFindAttribute(response, "media-left-margin-supported", IPP_TAG_INTEGER)) != NULL) {
11fe80
@@ -3900,7 +3905,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	left = 635;
11fe80
       snprintf(buffer, sizeof(buffer), "%d", left);
11fe80
       p->num_options = cupsAddOption("media-left-margin-default",
11fe80
-				     strdup(buffer),
11fe80
+				     buffer,
11fe80
 				     p->num_options, &(p->options));
11fe80
 
11fe80
       if ((attr = ippFindAttribute(response, "media-right-margin-supported", IPP_TAG_INTEGER)) != NULL) {
11fe80
@@ -3911,7 +3916,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	right = 635;
11fe80
       snprintf(buffer, sizeof(buffer), "%d", right);
11fe80
       p->num_options = cupsAddOption("media-right-margin-default",
11fe80
-				     strdup(buffer),
11fe80
+				     buffer,
11fe80
 				     p->num_options, &(p->options));
11fe80
 
11fe80
       if ((attr = ippFindAttribute(response, "media-top-margin-supported", IPP_TAG_INTEGER)) != NULL) {
11fe80
@@ -3922,7 +3927,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	top = 1270;
11fe80
       snprintf(buffer, sizeof(buffer), "%d", top);
11fe80
       p->num_options = cupsAddOption("media-top-margin-default",
11fe80
-				     strdup(buffer),
11fe80
+				     buffer,
11fe80
 				     p->num_options, &(p->options));
11fe80
 
11fe80
       debug_printf("Margins: Left: %d, Right: %d, Top: %d, Bottom: %d\n",
11fe80
@@ -3943,7 +3948,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	debug_printf("Best color space: %s\n",
11fe80
 		     best_color_space);
11fe80
 	p->num_options = cupsAddOption("print-color-mode-default",
11fe80
-				       strdup(best_color_space),
11fe80
+				       best_color_space,
11fe80
 				       p->num_options, &(p->options));
11fe80
       } else {
11fe80
 	debug_printf("No info about supported color spaces found!\n");
11fe80
@@ -3956,7 +3961,7 @@ create_remote_printer_entry (const char *queue_name,
11fe80
 	p->num_options = cupsAddOption("sides-default", "two-sided-long-edge",
11fe80
 				       p->num_options, &(p->options));
11fe80
 	
11fe80
-      p->num_options = cupsAddOption("output-format-default", strdup(pdl),
11fe80
+      p->num_options = cupsAddOption("output-format-default", pdl,
11fe80
 				     p->num_options, &(p->options));
11fe80
       p->num_options = cupsAddOption("make-and-model-default",
11fe80
 				     remove_bad_chars(make_model, 0),
11fe80
@@ -4119,7 +4124,7 @@ gboolean update_cups_queues(gpointer unused) {
11fe80
   char *disabled_str, *ptr, *prefix;
11fe80
   const char *loadedppd = NULL;
11fe80
   int pass_through_ppd;
11fe80
-  ppd_file_t *ppd;
11fe80
+  ppd_file_t *ppd = NULL;
11fe80
   ppd_choice_t *choice;
11fe80
   cups_file_t *in, *out;
11fe80
   char keyword[1024], *keyptr;
11fe80
@@ -4588,6 +4593,7 @@ gboolean update_cups_queues(gpointer unused) {
11fe80
 	  p->timeout = current_time + TIMEOUT_RETRY;
11fe80
 	  p->no_autosave = 0;
11fe80
 	  ppdClose(ppd);
11fe80
+          ppd = NULL;
11fe80
 	  unlink(loadedppd);
11fe80
 	  break;
11fe80
 	}
11fe80
@@ -4597,6 +4603,7 @@ gboolean update_cups_queues(gpointer unused) {
11fe80
 	  p->no_autosave = 0;
11fe80
 	  cupsFileClose(out);
11fe80
 	  ppdClose(ppd);
11fe80
+          ppd = NULL;
11fe80
 	  unlink(loadedppd);
11fe80
 	  break;
11fe80
 	}
11fe80
@@ -4710,6 +4717,7 @@ gboolean update_cups_queues(gpointer unused) {
11fe80
 	cupsFileClose(in);
11fe80
 	cupsFileClose(out);
11fe80
 	ppdClose(ppd);
11fe80
+        ppd = NULL;
11fe80
 	unlink(loadedppd);
11fe80
 	loadedppd = NULL;
11fe80
 	if (p->ppd)
11fe80
@@ -4748,8 +4756,8 @@ gboolean update_cups_queues(gpointer unused) {
11fe80
       /* Default option settings from printer entry */
11fe80
       for (i = 0; i < p->num_options; i ++)
11fe80
 	if (strcasecmp(p->options[i].name, "printer-is-shared"))
11fe80
-	  num_options = cupsAddOption(strdup(p->options[i].name),
11fe80
-				      strdup(p->options[i].value),
11fe80
+	  num_options = cupsAddOption(p->options[i].name,
11fe80
+				      p->options[i].value,
11fe80
 				      num_options, &options);
11fe80
       /* Encode option list into IPP attributes */
11fe80
       cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
11fe80
@@ -8342,6 +8350,9 @@ fail:
11fe80
 
11fe80
   if (local_printers_context) {
11fe80
     browse_poll_cancel_subscription (local_printers_context);
11fe80
+#ifdef HAVE_CUPS_2_0
11fe80
+    free(local_printers_context->server);
11fe80
+#endif
11fe80
     g_list_free_full (local_printers_context->printers,
11fe80
 		      browsepoll_printer_free);
11fe80
     free (local_printers_context);