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

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