Blame SOURCES/cups-memory-consumption.patch

50ac8c
diff --git a/cups/mark.c b/cups/mark.c
50ac8c
index dc2257f..b3d7d0d 100644
50ac8c
--- a/cups/mark.c
50ac8c
+++ b/cups/mark.c
50ac8c
@@ -890,9 +890,9 @@ ppd_mark_option(ppd_file_t *ppd,	/* I - PPD file */
50ac8c
 	  case PPD_CUSTOM_PASSWORD :
50ac8c
 	  case PPD_CUSTOM_STRING :
50ac8c
 	      if (cparam->current.custom_string)
50ac8c
-	        _cupsStrFree(cparam->current.custom_string);
50ac8c
+	        free(cparam->current.custom_string);
50ac8c
 
50ac8c
-	      cparam->current.custom_string = _cupsStrAlloc(choice + 7);
50ac8c
+	      cparam->current.custom_string = strdup(choice + 7);
50ac8c
 	      break;
50ac8c
 	}
50ac8c
       }
50ac8c
@@ -967,9 +967,9 @@ ppd_mark_option(ppd_file_t *ppd,	/* I - PPD file */
50ac8c
 	  case PPD_CUSTOM_PASSWORD :
50ac8c
 	  case PPD_CUSTOM_STRING :
50ac8c
 	      if (cparam->current.custom_string)
50ac8c
-		_cupsStrFree(cparam->current.custom_string);
50ac8c
+		free(cparam->current.custom_string);
50ac8c
 
50ac8c
-	      cparam->current.custom_string = _cupsStrRetain(val->value);
50ac8c
+	      cparam->current.custom_string = strdup(val->value);
50ac8c
 	      break;
50ac8c
 	}
50ac8c
       }
50ac8c
diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c
50ac8c
index ca1c773..072b9ff 100644
50ac8c
--- a/cups/ppd-cache.c
50ac8c
+++ b/cups/ppd-cache.c
50ac8c
@@ -199,24 +199,20 @@ _ppdCacheCreateWithFile(
50ac8c
     else if (!_cups_strcasecmp(line, "Filter"))
50ac8c
     {
50ac8c
       if (!pc->filters)
50ac8c
-        pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0,
50ac8c
-	                            (cups_acopy_func_t)_cupsStrAlloc,
50ac8c
-				    (cups_afree_func_t)_cupsStrFree);
50ac8c
+        pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
50ac8c
 
50ac8c
       cupsArrayAdd(pc->filters, value);
50ac8c
     }
50ac8c
     else if (!_cups_strcasecmp(line, "PreFilter"))
50ac8c
     {
50ac8c
       if (!pc->prefilters)
50ac8c
-        pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0,
50ac8c
-	                               (cups_acopy_func_t)_cupsStrAlloc,
50ac8c
-				       (cups_afree_func_t)_cupsStrFree);
50ac8c
+        pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
50ac8c
 
50ac8c
       cupsArrayAdd(pc->prefilters, value);
50ac8c
     }
50ac8c
     else if (!_cups_strcasecmp(line, "Product"))
50ac8c
     {
50ac8c
-      pc->product = _cupsStrAlloc(value);
50ac8c
+      pc->product = strdup(value);
50ac8c
     }
50ac8c
     else if (!_cups_strcasecmp(line, "SingleFile"))
50ac8c
     {
50ac8c
@@ -316,8 +312,8 @@ _ppdCacheCreateWithFile(
50ac8c
       }
50ac8c
 
50ac8c
       map      = pc->bins + pc->num_bins;
50ac8c
-      map->pwg = _cupsStrAlloc(pwg_keyword);
50ac8c
-      map->ppd = _cupsStrAlloc(ppd_keyword);
50ac8c
+      map->pwg = strdup(pwg_keyword);
50ac8c
+      map->ppd = strdup(ppd_keyword);
50ac8c
 
50ac8c
       pc->num_bins ++;
50ac8c
     }
50ac8c
@@ -371,8 +367,8 @@ _ppdCacheCreateWithFile(
50ac8c
 	goto create_error;
50ac8c
       }
50ac8c
 
50ac8c
-      size->map.pwg = _cupsStrAlloc(pwg_keyword);
50ac8c
-      size->map.ppd = _cupsStrAlloc(ppd_keyword);
50ac8c
+      size->map.pwg = strdup(pwg_keyword);
50ac8c
+      size->map.ppd = strdup(ppd_keyword);
50ac8c
 
50ac8c
       pc->num_sizes ++;
50ac8c
     }
50ac8c
@@ -400,15 +396,15 @@ _ppdCacheCreateWithFile(
50ac8c
 
50ac8c
       _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "max",
50ac8c
 		       pc->custom_max_width, pc->custom_max_length);
50ac8c
-      pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword);
50ac8c
+      pc->custom_max_keyword = strdup(pwg_keyword);
50ac8c
 
50ac8c
       _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "min",
50ac8c
 		       pc->custom_min_width, pc->custom_min_length);
50ac8c
-      pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword);
50ac8c
+      pc->custom_min_keyword = strdup(pwg_keyword);
50ac8c
     }
50ac8c
     else if (!_cups_strcasecmp(line, "SourceOption"))
50ac8c
     {
50ac8c
-      pc->source_option = _cupsStrAlloc(value);
50ac8c
+      pc->source_option = strdup(value);
50ac8c
     }
50ac8c
     else if (!_cups_strcasecmp(line, "NumSources"))
50ac8c
     {
50ac8c
@@ -455,8 +451,8 @@ _ppdCacheCreateWithFile(
50ac8c
       }
50ac8c
 
50ac8c
       map      = pc->sources + pc->num_sources;
50ac8c
-      map->pwg = _cupsStrAlloc(pwg_keyword);
50ac8c
-      map->ppd = _cupsStrAlloc(ppd_keyword);
50ac8c
+      map->pwg = strdup(pwg_keyword);
50ac8c
+      map->ppd = strdup(ppd_keyword);
50ac8c
 
50ac8c
       pc->num_sources ++;
50ac8c
     }
50ac8c
@@ -504,8 +500,8 @@ _ppdCacheCreateWithFile(
50ac8c
       }
50ac8c
 
50ac8c
       map      = pc->types + pc->num_types;
50ac8c
-      map->pwg = _cupsStrAlloc(pwg_keyword);
50ac8c
-      map->ppd = _cupsStrAlloc(ppd_keyword);
50ac8c
+      map->pwg = strdup(pwg_keyword);
50ac8c
+      map->ppd = strdup(ppd_keyword);
50ac8c
 
50ac8c
       pc->num_types ++;
50ac8c
     }
50ac8c
@@ -535,13 +531,13 @@ _ppdCacheCreateWithFile(
50ac8c
 	                   pc->presets[print_color_mode] + print_quality);
50ac8c
     }
50ac8c
     else if (!_cups_strcasecmp(line, "SidesOption"))
50ac8c
-      pc->sides_option = _cupsStrAlloc(value);
50ac8c
+      pc->sides_option = strdup(value);
50ac8c
     else if (!_cups_strcasecmp(line, "Sides1Sided"))
50ac8c
-      pc->sides_1sided = _cupsStrAlloc(value);
50ac8c
+      pc->sides_1sided = strdup(value);
50ac8c
     else if (!_cups_strcasecmp(line, "Sides2SidedLong"))
50ac8c
-      pc->sides_2sided_long = _cupsStrAlloc(value);
50ac8c
+      pc->sides_2sided_long = strdup(value);
50ac8c
     else if (!_cups_strcasecmp(line, "Sides2SidedShort"))
50ac8c
-      pc->sides_2sided_short = _cupsStrAlloc(value);
50ac8c
+      pc->sides_2sided_short = strdup(value);
50ac8c
     else if (!_cups_strcasecmp(line, "Finishings"))
50ac8c
     {
50ac8c
       if (!pc->finishings)
50ac8c
@@ -796,8 +792,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 	  */
50ac8c
 
50ac8c
 	  new_size = old_size;
50ac8c
-	  _cupsStrFree(old_size->map.ppd);
50ac8c
-	  _cupsStrFree(old_size->map.pwg);
50ac8c
+	  free(old_size->map.ppd);
50ac8c
+	  free(old_size->map.pwg);
50ac8c
 	}
50ac8c
       }
50ac8c
 
50ac8c
@@ -818,8 +814,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 	* Save this size...
50ac8c
 	*/
50ac8c
 
50ac8c
-	new_size->map.ppd = _cupsStrAlloc(ppd_size->name);
50ac8c
-	new_size->map.pwg = _cupsStrAlloc(pwg_name);
50ac8c
+	new_size->map.ppd = strdup(ppd_size->name);
50ac8c
+	new_size->map.pwg = strdup(pwg_name);
50ac8c
 	new_size->width   = new_width;
50ac8c
 	new_size->length  = new_length;
50ac8c
 	new_size->left    = new_left;
50ac8c
@@ -839,14 +835,14 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
     _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "max",
50ac8c
 		     _PWG_FROMPTS(ppd->custom_max[0]),
50ac8c
 		     _PWG_FROMPTS(ppd->custom_max[1]));
50ac8c
-    pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword);
50ac8c
+    pc->custom_max_keyword = strdup(pwg_keyword);
50ac8c
     pc->custom_max_width   = _PWG_FROMPTS(ppd->custom_max[0]);
50ac8c
     pc->custom_max_length  = _PWG_FROMPTS(ppd->custom_max[1]);
50ac8c
 
50ac8c
     _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "min",
50ac8c
 		     _PWG_FROMPTS(ppd->custom_min[0]),
50ac8c
 		     _PWG_FROMPTS(ppd->custom_min[1]));
50ac8c
-    pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword);
50ac8c
+    pc->custom_min_keyword = strdup(pwg_keyword);
50ac8c
     pc->custom_min_width   = _PWG_FROMPTS(ppd->custom_min[0]);
50ac8c
     pc->custom_min_length  = _PWG_FROMPTS(ppd->custom_min[1]);
50ac8c
 
50ac8c
@@ -865,7 +861,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 
50ac8c
   if (input_slot)
50ac8c
   {
50ac8c
-    pc->source_option = _cupsStrAlloc(input_slot->keyword);
50ac8c
+    pc->source_option = strdup(input_slot->keyword);
50ac8c
 
50ac8c
     if ((pc->sources = calloc(input_slot->num_choices,
50ac8c
                                sizeof(_pwg_map_t))) == NULL)
50ac8c
@@ -918,8 +914,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 	                  "_");
50ac8c
       }
50ac8c
 
50ac8c
-      map->pwg = _cupsStrAlloc(pwg_name);
50ac8c
-      map->ppd = _cupsStrAlloc(choice->choice);
50ac8c
+      map->pwg = strdup(pwg_name);
50ac8c
+      map->ppd = strdup(choice->choice);
50ac8c
     }
50ac8c
   }
50ac8c
 
50ac8c
@@ -983,8 +979,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 	                  "_");
50ac8c
       }
50ac8c
 
50ac8c
-      map->pwg = _cupsStrAlloc(pwg_name);
50ac8c
-      map->ppd = _cupsStrAlloc(choice->choice);
50ac8c
+      map->pwg = strdup(pwg_name);
50ac8c
+      map->ppd = strdup(choice->choice);
50ac8c
     }
50ac8c
   }
50ac8c
 
50ac8c
@@ -1011,8 +1007,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
     {
50ac8c
       pwg_unppdize_name(choice->choice, pwg_keyword, sizeof(pwg_keyword), "_");
50ac8c
 
50ac8c
-      map->pwg = _cupsStrAlloc(pwg_keyword);
50ac8c
-      map->ppd = _cupsStrAlloc(choice->choice);
50ac8c
+      map->pwg = strdup(pwg_keyword);
50ac8c
+      map->ppd = strdup(choice->choice);
50ac8c
     }
50ac8c
   }
50ac8c
 
50ac8c
@@ -1227,7 +1223,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 
50ac8c
   if (duplex)
50ac8c
   {
50ac8c
-    pc->sides_option = _cupsStrAlloc(duplex->keyword);
50ac8c
+    pc->sides_option = strdup(duplex->keyword);
50ac8c
 
50ac8c
     for (i = duplex->num_choices, choice = duplex->choices;
50ac8c
          i > 0;
50ac8c
@@ -1235,16 +1231,16 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
     {
50ac8c
       if ((!_cups_strcasecmp(choice->choice, "None") ||
50ac8c
 	   !_cups_strcasecmp(choice->choice, "False")) && !pc->sides_1sided)
50ac8c
-        pc->sides_1sided = _cupsStrAlloc(choice->choice);
50ac8c
+        pc->sides_1sided = strdup(choice->choice);
50ac8c
       else if ((!_cups_strcasecmp(choice->choice, "DuplexNoTumble") ||
50ac8c
 	        !_cups_strcasecmp(choice->choice, "LongEdge") ||
50ac8c
 	        !_cups_strcasecmp(choice->choice, "Top")) && !pc->sides_2sided_long)
50ac8c
-        pc->sides_2sided_long = _cupsStrAlloc(choice->choice);
50ac8c
+        pc->sides_2sided_long = strdup(choice->choice);
50ac8c
       else if ((!_cups_strcasecmp(choice->choice, "DuplexTumble") ||
50ac8c
 	        !_cups_strcasecmp(choice->choice, "ShortEdge") ||
50ac8c
 	        !_cups_strcasecmp(choice->choice, "Bottom")) &&
50ac8c
 	       !pc->sides_2sided_short)
50ac8c
-        pc->sides_2sided_short = _cupsStrAlloc(choice->choice);
50ac8c
+        pc->sides_2sided_short = strdup(choice->choice);
50ac8c
     }
50ac8c
   }
50ac8c
 
50ac8c
@@ -1252,9 +1248,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
   * Copy filters and pre-filters...
50ac8c
   */
50ac8c
 
50ac8c
-  pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0,
50ac8c
-			      (cups_acopy_func_t)_cupsStrAlloc,
50ac8c
-			      (cups_afree_func_t)_cupsStrFree);
50ac8c
+  pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
50ac8c
 
50ac8c
   cupsArrayAdd(pc->filters,
50ac8c
                "application/vnd.cups-raw application/octet-stream 0 -");
50ac8c
@@ -1311,9 +1305,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
 
50ac8c
   if ((ppd_attr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL)
50ac8c
   {
50ac8c
-    pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0,
50ac8c
-				   (cups_acopy_func_t)_cupsStrAlloc,
50ac8c
-				   (cups_afree_func_t)_cupsStrFree);
50ac8c
+    pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
50ac8c
 
50ac8c
     do
50ac8c
     {
50ac8c
@@ -1330,7 +1322,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
   */
50ac8c
 
50ac8c
   if (ppd->product)
50ac8c
-    pc->product = _cupsStrAlloc(ppd->product);
50ac8c
+    pc->product = strdup(ppd->product);
50ac8c
 
50ac8c
  /*
50ac8c
   * Copy finishings mapping data...
50ac8c
@@ -1415,8 +1407,8 @@ _ppdCacheDestroy(_ppd_cache_t *pc)	/* I - PPD cache and mapping data */
50ac8c
   {
50ac8c
     for (i = pc->num_bins, map = pc->bins; i > 0; i --, map ++)
50ac8c
     {
50ac8c
-      _cupsStrFree(map->pwg);
50ac8c
-      _cupsStrFree(map->ppd);
50ac8c
+      free(map->pwg);
50ac8c
+      free(map->ppd);
50ac8c
     }
50ac8c
 
50ac8c
     free(pc->bins);
50ac8c
@@ -1426,22 +1418,21 @@ _ppdCacheDestroy(_ppd_cache_t *pc)	/* I - PPD cache and mapping data */
50ac8c
   {
50ac8c
     for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++)
50ac8c
     {
50ac8c
-      _cupsStrFree(size->map.pwg);
50ac8c
-      _cupsStrFree(size->map.ppd);
50ac8c
+      free(size->map.pwg);
50ac8c
+      free(size->map.ppd);
50ac8c
     }
50ac8c
 
50ac8c
     free(pc->sizes);
50ac8c
   }
50ac8c
 
50ac8c
-  if (pc->source_option)
50ac8c
-    _cupsStrFree(pc->source_option);
50ac8c
+  free(pc->source_option);
50ac8c
 
50ac8c
   if (pc->sources)
50ac8c
   {
50ac8c
     for (i = pc->num_sources, map = pc->sources; i > 0; i --, map ++)
50ac8c
     {
50ac8c
-      _cupsStrFree(map->pwg);
50ac8c
-      _cupsStrFree(map->ppd);
50ac8c
+      free(map->pwg);
50ac8c
+      free(map->ppd);
50ac8c
     }
50ac8c
 
50ac8c
     free(pc->sources);
50ac8c
@@ -1451,20 +1442,17 @@ _ppdCacheDestroy(_ppd_cache_t *pc)	/* I - PPD cache and mapping data */
50ac8c
   {
50ac8c
     for (i = pc->num_types, map = pc->types; i > 0; i --, map ++)
50ac8c
     {
50ac8c
-      _cupsStrFree(map->pwg);
50ac8c
-      _cupsStrFree(map->ppd);
50ac8c
+      free(map->pwg);
50ac8c
+      free(map->ppd);
50ac8c
     }
50ac8c
 
50ac8c
     free(pc->types);
50ac8c
   }
50ac8c
 
50ac8c
-  if (pc->custom_max_keyword)
50ac8c
-    _cupsStrFree(pc->custom_max_keyword);
50ac8c
-
50ac8c
-  if (pc->custom_min_keyword)
50ac8c
-    _cupsStrFree(pc->custom_min_keyword);
50ac8c
+  free(pc->custom_max_keyword);
50ac8c
+  free(pc->custom_min_keyword);
50ac8c
 
50ac8c
-  _cupsStrFree(pc->product);
50ac8c
+  free(pc->product);
50ac8c
   cupsArrayDelete(pc->filters);
50ac8c
   cupsArrayDelete(pc->prefilters);
50ac8c
   cupsArrayDelete(pc->finishings);
50ac8c
diff --git a/cups/ppd.c b/cups/ppd.c
50ac8c
index dd18cc2..c0e55a3 100644
50ac8c
--- a/cups/ppd.c
50ac8c
+++ b/cups/ppd.c
50ac8c
@@ -78,8 +78,6 @@
50ac8c
 #  define WRITE_BINARY	"w"		/* Open a binary file for writing */
50ac8c
 #endif /* WIN32 || __EMX__ */
50ac8c
 
50ac8c
-#define ppd_free(p)	if (p) free(p)	/* Safe free macro */
50ac8c
-
50ac8c
 #define PPD_KEYWORD	1		/* Line contained a keyword */
50ac8c
 #define PPD_OPTION	2		/* Line contained an option name */
50ac8c
 #define PPD_TEXT	4		/* Line contained human-readable text */
50ac8c
@@ -142,7 +140,6 @@ void
50ac8c
 ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
 {
50ac8c
   int			i;		/* Looping var */
50ac8c
-  ppd_emul_t		*emul;		/* Current emulation */
50ac8c
   ppd_group_t		*group;		/* Current group */
50ac8c
   char			**font;		/* Current font */
50ac8c
   ppd_attr_t		**attr;		/* Current attribute */
50ac8c
@@ -161,28 +158,12 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
   * Free all strings at the top level...
50ac8c
   */
50ac8c
 
50ac8c
-  _cupsStrFree(ppd->lang_encoding);
50ac8c
-  _cupsStrFree(ppd->nickname);
50ac8c
-  if (ppd->patches)
50ac8c
-    free(ppd->patches);
50ac8c
-  _cupsStrFree(ppd->jcl_begin);
50ac8c
-  _cupsStrFree(ppd->jcl_end);
50ac8c
-  _cupsStrFree(ppd->jcl_ps);
50ac8c
-
50ac8c
- /*
50ac8c
-  * Free any emulations...
50ac8c
-  */
50ac8c
-
50ac8c
-  if (ppd->num_emulations > 0)
50ac8c
-  {
50ac8c
-    for (i = ppd->num_emulations, emul = ppd->emulations; i > 0; i --, emul ++)
50ac8c
-    {
50ac8c
-      _cupsStrFree(emul->start);
50ac8c
-      _cupsStrFree(emul->stop);
50ac8c
-    }
50ac8c
-
50ac8c
-    ppd_free(ppd->emulations);
50ac8c
-  }
50ac8c
+  free(ppd->lang_encoding);
50ac8c
+  free(ppd->nickname);
50ac8c
+  free(ppd->patches);
50ac8c
+  free(ppd->jcl_begin);
50ac8c
+  free(ppd->jcl_end);
50ac8c
+  free(ppd->jcl_ps);
50ac8c
 
50ac8c
  /*
50ac8c
   * Free any UI groups, subgroups, and options...
50ac8c
@@ -193,7 +174,7 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
     for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
50ac8c
       ppd_free_group(group);
50ac8c
 
50ac8c
-    ppd_free(ppd->groups);
50ac8c
+    free(ppd->groups);
50ac8c
   }
50ac8c
 
50ac8c
   cupsArrayDelete(ppd->options);
50ac8c
@@ -204,14 +185,14 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
   */
50ac8c
 
50ac8c
   if (ppd->num_sizes > 0)
50ac8c
-    ppd_free(ppd->sizes);
50ac8c
+    free(ppd->sizes);
50ac8c
 
50ac8c
  /*
50ac8c
   * Free any constraints...
50ac8c
   */
50ac8c
 
50ac8c
   if (ppd->num_consts > 0)
50ac8c
-    ppd_free(ppd->consts);
50ac8c
+    free(ppd->consts);
50ac8c
 
50ac8c
  /*
50ac8c
   * Free any filters...
50ac8c
@@ -226,9 +207,9 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
   if (ppd->num_fonts > 0)
50ac8c
   {
50ac8c
     for (i = ppd->num_fonts, font = ppd->fonts; i > 0; i --, font ++)
50ac8c
-      _cupsStrFree(*font);
50ac8c
+      free(*font);
50ac8c
 
50ac8c
-    ppd_free(ppd->fonts);
50ac8c
+    free(ppd->fonts);
50ac8c
   }
50ac8c
 
50ac8c
  /*
50ac8c
@@ -236,7 +217,7 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
   */
50ac8c
 
50ac8c
   if (ppd->num_profiles > 0)
50ac8c
-    ppd_free(ppd->profiles);
50ac8c
+    free(ppd->profiles);
50ac8c
 
50ac8c
  /*
50ac8c
   * Free any attributes...
50ac8c
@@ -246,11 +227,11 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
   {
50ac8c
     for (i = ppd->num_attrs, attr = ppd->attrs; i > 0; i --, attr ++)
50ac8c
     {
50ac8c
-      _cupsStrFree((*attr)->value);
50ac8c
-      ppd_free(*attr);
50ac8c
+      free((*attr)->value);
50ac8c
+      free(*attr);
50ac8c
     }
50ac8c
 
50ac8c
-    ppd_free(ppd->attrs);
50ac8c
+    free(ppd->attrs);
50ac8c
   }
50ac8c
 
50ac8c
   cupsArrayDelete(ppd->sorted_attrs);
50ac8c
@@ -272,7 +253,7 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
         case PPD_CUSTOM_PASSCODE :
50ac8c
         case PPD_CUSTOM_PASSWORD :
50ac8c
         case PPD_CUSTOM_STRING :
50ac8c
-            _cupsStrFree(cparam->current.custom_string);
50ac8c
+            free(cparam->current.custom_string);
50ac8c
 	    break;
50ac8c
 
50ac8c
 	default :
50ac8c
@@ -320,7 +301,7 @@ ppdClose(ppd_file_t *ppd)		/* I - PPD file record */
50ac8c
   * Free the whole record...
50ac8c
   */
50ac8c
 
50ac8c
-  ppd_free(ppd);
50ac8c
+  free(ppd);
50ac8c
 }
50ac8c
 
50ac8c
 
50ac8c
@@ -426,7 +407,6 @@ _ppdOpen(
50ac8c
     _ppd_localization_t	localization)	/* I - Localization to load */
50ac8c
 {
50ac8c
   int			i, j, k;	/* Looping vars */
50ac8c
-  int			count;		/* Temporary count */
50ac8c
   _ppd_line_t		line;		/* Line buffer */
50ac8c
   ppd_file_t		*ppd;		/* PPD file record */
50ac8c
   ppd_group_t		*group,		/* Current group */
50ac8c
@@ -444,7 +424,6 @@ _ppdOpen(
50ac8c
 					/* Human-readable text from file */
50ac8c
 			*string,	/* Code/text from file */
50ac8c
 			*sptr,		/* Pointer into string */
50ac8c
-			*nameptr,	/* Pointer into name */
50ac8c
 			*temp,		/* Temporary string pointer */
50ac8c
 			**tempfonts;	/* Temporary fonts pointer */
50ac8c
   float			order;		/* Order dependency number */
50ac8c
@@ -592,16 +571,14 @@ _ppdOpen(
50ac8c
     if (cg->ppd_status == PPD_OK)
50ac8c
       cg->ppd_status = PPD_MISSING_PPDADOBE4;
50ac8c
 
50ac8c
-    _cupsStrFree(string);
50ac8c
-    ppd_free(line.buffer);
50ac8c
+    free(string);
50ac8c
+    free(line.buffer);
50ac8c
 
50ac8c
     return (NULL);
50ac8c
   }
50ac8c
 
50ac8c
   DEBUG_printf(("2_ppdOpen: keyword=%s, string=%p", keyword, string));
50ac8c
 
50ac8c
-  _cupsStrFree(string);
50ac8c
-
50ac8c
  /*
50ac8c
   * Allocate memory for the PPD file record...
50ac8c
   */
50ac8c
@@ -610,8 +587,8 @@ _ppdOpen(
50ac8c
   {
50ac8c
     cg->ppd_status = PPD_ALLOC_ERROR;
50ac8c
 
50ac8c
-    _cupsStrFree(string);
50ac8c
-    ppd_free(line.buffer);
50ac8c
+    free(string);
50ac8c
+    free(line.buffer);
50ac8c
 
50ac8c
     return (NULL);
50ac8c
   }
50ac8c
@@ -694,6 +671,8 @@ _ppdOpen(
50ac8c
 	   strncmp(ll, keyword, ll_len)))
50ac8c
       {
50ac8c
 	DEBUG_printf(("2_ppdOpen: Ignoring localization: \"%s\"\n", keyword));
50ac8c
+	free(string);
50ac8c
+	string = NULL;
50ac8c
 	continue;
50ac8c
       }
50ac8c
       else if (localization == _PPD_LOCALIZATION_ICC_PROFILES)
50ac8c
@@ -713,6 +692,8 @@ _ppdOpen(
50ac8c
 	if (i >= (int)(sizeof(color_keywords) / sizeof(color_keywords[0])))
50ac8c
 	{
50ac8c
 	  DEBUG_printf(("2_ppdOpen: Ignoring localization: \"%s\"\n", keyword));
50ac8c
+	  free(string);
50ac8c
+	  string = NULL;
50ac8c
 	  continue;
50ac8c
 	}
50ac8c
       }
50ac8c
@@ -808,7 +789,7 @@ _ppdOpen(
50ac8c
       * Say all PPD files are UTF-8, since we convert to UTF-8...
50ac8c
       */
50ac8c
 
50ac8c
-      ppd->lang_encoding = _cupsStrAlloc("UTF-8");
50ac8c
+      ppd->lang_encoding = strdup("UTF-8");
50ac8c
       encoding           = _ppdGetEncoding(string);
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "LanguageVersion"))
50ac8c
@@ -829,10 +810,10 @@ _ppdOpen(
50ac8c
 
50ac8c
 
50ac8c
         cupsCharsetToUTF8(utf8, string, sizeof(utf8), encoding);
50ac8c
-	ppd->nickname = _cupsStrAlloc((char *)utf8);
50ac8c
+	ppd->nickname = strdup((char *)utf8);
50ac8c
       }
50ac8c
       else
50ac8c
-        ppd->nickname = _cupsStrAlloc(string);
50ac8c
+        ppd->nickname = strdup(string);
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "Product"))
50ac8c
       ppd->product = string;
50ac8c
@@ -842,17 +823,17 @@ _ppdOpen(
50ac8c
       ppd->ttrasterizer = string;
50ac8c
     else if (!strcmp(keyword, "JCLBegin"))
50ac8c
     {
50ac8c
-      ppd->jcl_begin = _cupsStrAlloc(string);
50ac8c
+      ppd->jcl_begin = strdup(string);
50ac8c
       ppd_decode(ppd->jcl_begin);	/* Decode quoted string */
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "JCLEnd"))
50ac8c
     {
50ac8c
-      ppd->jcl_end = _cupsStrAlloc(string);
50ac8c
+      ppd->jcl_end = strdup(string);
50ac8c
       ppd_decode(ppd->jcl_end);		/* Decode quoted string */
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "JCLToPSInterpreter"))
50ac8c
     {
50ac8c
-      ppd->jcl_ps = _cupsStrAlloc(string);
50ac8c
+      ppd->jcl_ps = strdup(string);
50ac8c
       ppd_decode(ppd->jcl_ps);		/* Decode quoted string */
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "AccurateScreensSupport"))
50ac8c
@@ -921,10 +902,10 @@ _ppdOpen(
50ac8c
       ppd->num_filters ++;
50ac8c
 
50ac8c
      /*
50ac8c
-      * Retain a copy of the filter string...
50ac8c
+      * Make a copy of the filter string...
50ac8c
       */
50ac8c
 
50ac8c
-      *filter = _cupsStrRetain(string);
50ac8c
+      *filter = strdup(string);
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "Throughput"))
50ac8c
       ppd->throughput = atoi(string);
50ac8c
@@ -948,7 +929,7 @@ _ppdOpen(
50ac8c
       }
50ac8c
 
50ac8c
       ppd->fonts                 = tempfonts;
50ac8c
-      ppd->fonts[ppd->num_fonts] = _cupsStrAlloc(name);
50ac8c
+      ppd->fonts[ppd->num_fonts] = strdup(name);
50ac8c
       ppd->num_fonts ++;
50ac8c
     }
50ac8c
     else if (!strncmp(keyword, "ParamCustom", 11))
50ac8c
@@ -1113,7 +1094,7 @@ _ppdOpen(
50ac8c
 	strlcpy(choice->text, text[0] ? text : _("Custom"),
50ac8c
 		sizeof(choice->text));
50ac8c
 
50ac8c
-	choice->code = _cupsStrAlloc(string);
50ac8c
+	choice->code = strdup(string);
50ac8c
 
50ac8c
 	if (custom_option->section == PPD_ORDER_JCL)
50ac8c
 	  ppd_decode(choice->code);
50ac8c
@@ -1162,59 +1143,23 @@ _ppdOpen(
50ac8c
       else if (!strcmp(string, "Plus90"))
50ac8c
         ppd->landscape = 90;
50ac8c
     }
50ac8c
-    else if (!strcmp(keyword, "Emulators") && string)
50ac8c
+    else if (!strcmp(keyword, "Emulators") && string && ppd->num_emulations == 0)
50ac8c
     {
50ac8c
-      for (count = 1, sptr = string; sptr != NULL;)
50ac8c
-        if ((sptr = strchr(sptr, ' ')) != NULL)
50ac8c
-	{
50ac8c
-	  count ++;
50ac8c
-	  while (*sptr == ' ')
50ac8c
-	    sptr ++;
50ac8c
-	}
50ac8c
-
50ac8c
-      ppd->num_emulations = count;
50ac8c
-      if ((ppd->emulations = calloc(count, sizeof(ppd_emul_t))) == NULL)
50ac8c
-      {
50ac8c
-        cg->ppd_status = PPD_ALLOC_ERROR;
50ac8c
-
50ac8c
-	goto error;
50ac8c
-      }
50ac8c
-
50ac8c
-      for (i = 0, sptr = string; i < count; i ++)
50ac8c
-      {
50ac8c
-        for (nameptr = ppd->emulations[i].name;
50ac8c
-	     *sptr != '\0' && *sptr != ' ';
50ac8c
-	     sptr ++)
50ac8c
-	  if (nameptr < (ppd->emulations[i].name + sizeof(ppd->emulations[i].name) - 1))
50ac8c
-	    *nameptr++ = *sptr;
50ac8c
-
50ac8c
-	*nameptr = '\0';
50ac8c
-
50ac8c
-	while (*sptr == ' ')
50ac8c
-	  sptr ++;
50ac8c
-      }
50ac8c
-    }
50ac8c
-    else if (!strncmp(keyword, "StartEmulator_", 14))
50ac8c
-    {
50ac8c
-      ppd_decode(string);
50ac8c
+     /*
50ac8c
+      * Issue #5562: Samsung printer drivers incorrectly use Emulators keyword
50ac8c
+      *              to configure themselves
50ac8c
+      *
50ac8c
+      * The Emulators keyword was loaded but never used by anything in CUPS,
50ac8c
+      * and has no valid purpose in CUPS.  The old code was removed due to a
50ac8c
+      * memory leak (Issue #5475), so the following (new) code supports a single
50ac8c
+      * name for the Emulators keyword, allowing these drivers to work until we
50ac8c
+      * remove PPD and driver support entirely in a future version of CUPS.
50ac8c
+      */
50ac8c
 
50ac8c
-      for (i = 0; i < ppd->num_emulations; i ++)
50ac8c
-        if (!strcmp(keyword + 14, ppd->emulations[i].name))
50ac8c
-	{
50ac8c
-	  ppd->emulations[i].start = string;
50ac8c
-	  string = NULL;
50ac8c
-	}
50ac8c
-    }
50ac8c
-    else if (!strncmp(keyword, "StopEmulator_", 13))
50ac8c
-    {
50ac8c
-      ppd_decode(string);
50ac8c
+      ppd->num_emulations = 1;
50ac8c
+      ppd->emulations     = calloc(1, sizeof(ppd_emul_t));
50ac8c
 
50ac8c
-      for (i = 0; i < ppd->num_emulations; i ++)
50ac8c
-        if (!strcmp(keyword + 13, ppd->emulations[i].name))
50ac8c
-	{
50ac8c
-	  ppd->emulations[i].stop = string;
50ac8c
-	  string = NULL;
50ac8c
-	}
50ac8c
+      strlcpy(ppd->emulations[0].name, string, sizeof(ppd->emulations[0].name));
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "JobPatchFile"))
50ac8c
     {
50ac8c
@@ -1369,7 +1314,7 @@ _ppdOpen(
50ac8c
 
50ac8c
       option->section = PPD_ORDER_ANY;
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
 
50ac8c
      /*
50ac8c
@@ -1397,7 +1342,7 @@ _ppdOpen(
50ac8c
 	strlcpy(choice->text,
50ac8c
 	        custom_attr->text[0] ? custom_attr->text : _("Custom"),
50ac8c
 		sizeof(choice->text));
50ac8c
-        choice->code = _cupsStrRetain(custom_attr->value);
50ac8c
+        choice->code = strdup(custom_attr->value);
50ac8c
       }
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "JCLOpenUI"))
50ac8c
@@ -1476,7 +1421,7 @@ _ppdOpen(
50ac8c
       option->section = PPD_ORDER_JCL;
50ac8c
       group = NULL;
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
 
50ac8c
      /*
50ac8c
@@ -1500,14 +1445,14 @@ _ppdOpen(
50ac8c
 	strlcpy(choice->text,
50ac8c
 	        custom_attr->text[0] ? custom_attr->text : _("Custom"),
50ac8c
 		sizeof(choice->text));
50ac8c
-        choice->code = _cupsStrRetain(custom_attr->value);
50ac8c
+        choice->code = strdup(custom_attr->value);
50ac8c
       }
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "CloseUI") || !strcmp(keyword, "JCLCloseUI"))
50ac8c
     {
50ac8c
       option = NULL;
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "OpenGroup"))
50ac8c
@@ -1554,14 +1499,14 @@ _ppdOpen(
50ac8c
       if (group == NULL)
50ac8c
 	goto error;
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "CloseGroup"))
50ac8c
     {
50ac8c
       group = NULL;
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "OrderDependency"))
50ac8c
@@ -1619,7 +1564,7 @@ _ppdOpen(
50ac8c
 	option->order   = order;
50ac8c
       }
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (!strncmp(keyword, "Default", 7))
50ac8c
@@ -1863,7 +1808,7 @@ _ppdOpen(
50ac8c
       * Don't add this one as an attribute...
50ac8c
       */
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "PaperDimension"))
50ac8c
@@ -1885,7 +1830,7 @@ _ppdOpen(
50ac8c
       size->width  = (float)_cupsStrScand(string, &sptr, loc);
50ac8c
       size->length = (float)_cupsStrScand(sptr, NULL, loc);
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (!strcmp(keyword, "ImageableArea"))
50ac8c
@@ -1909,7 +1854,7 @@ _ppdOpen(
50ac8c
       size->right  = (float)_cupsStrScand(sptr, &sptr, loc);
50ac8c
       size->top    = (float)_cupsStrScand(sptr, NULL, loc);
50ac8c
 
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
       string = NULL;
50ac8c
     }
50ac8c
     else if (option != NULL &&
50ac8c
@@ -1965,7 +1910,7 @@ _ppdOpen(
50ac8c
         (mask & (PPD_KEYWORD | PPD_STRING)) == (PPD_KEYWORD | PPD_STRING))
50ac8c
       ppd_add_attr(ppd, keyword, name, text, string);
50ac8c
     else
50ac8c
-      _cupsStrFree(string);
50ac8c
+      free(string);
50ac8c
   }
50ac8c
 
50ac8c
  /*
50ac8c
@@ -1978,7 +1923,8 @@ _ppdOpen(
50ac8c
     goto error;
50ac8c
   }
50ac8c
 
50ac8c
-  ppd_free(line.buffer);
50ac8c
+  free(string);
50ac8c
+  free(line.buffer);
50ac8c
 
50ac8c
  /*
50ac8c
   * Reset language preferences...
50ac8c
@@ -2060,8 +2006,8 @@ _ppdOpen(
50ac8c
 
50ac8c
   error:
50ac8c
 
50ac8c
-  _cupsStrFree(string);
50ac8c
-  ppd_free(line.buffer);
50ac8c
+  free(string);
50ac8c
+  free(line.buffer);
50ac8c
 
50ac8c
   ppdClose(ppd);
50ac8c
 
50ac8c
@@ -2500,9 +2446,9 @@ ppd_free_filters(ppd_file_t *ppd)	/* I - PPD file */
50ac8c
   if (ppd->num_filters > 0)
50ac8c
   {
50ac8c
     for (i = ppd->num_filters, filter = ppd->filters; i > 0; i --, filter ++)
50ac8c
-      _cupsStrFree(*filter);
50ac8c
+      free(*filter);
50ac8c
 
50ac8c
-    ppd_free(ppd->filters);
50ac8c
+    free(ppd->filters);
50ac8c
 
50ac8c
     ppd->num_filters = 0;
50ac8c
     ppd->filters     = NULL;
50ac8c
@@ -2529,7 +2475,7 @@ ppd_free_group(ppd_group_t *group)	/* I - Group to free */
50ac8c
 	 i --, option ++)
50ac8c
       ppd_free_option(option);
50ac8c
 
50ac8c
-    ppd_free(group->options);
50ac8c
+    free(group->options);
50ac8c
   }
50ac8c
 
50ac8c
   if (group->num_subgroups > 0)
50ac8c
@@ -2539,7 +2485,7 @@ ppd_free_group(ppd_group_t *group)	/* I - Group to free */
50ac8c
 	 i --, subgroup ++)
50ac8c
       ppd_free_group(subgroup);
50ac8c
 
50ac8c
-    ppd_free(group->subgroups);
50ac8c
+    free(group->subgroups);
50ac8c
   }
50ac8c
 }
50ac8c
 
50ac8c
@@ -2561,10 +2507,10 @@ ppd_free_option(ppd_option_t *option)	/* I - Option to free */
50ac8c
          i > 0;
50ac8c
          i --, choice ++)
50ac8c
     {
50ac8c
-      _cupsStrFree(choice->code);
50ac8c
+      free(choice->code);
50ac8c
     }
50ac8c
 
50ac8c
-    ppd_free(option->choices);
50ac8c
+    free(option->choices);
50ac8c
   }
50ac8c
 }
50ac8c
 
50ac8c
@@ -3262,7 +3208,7 @@ ppd_read(cups_file_t    *fp,		/* I - File to read from */
50ac8c
 	lineptr ++;
50ac8c
       }
50ac8c
 
50ac8c
-      *string = _cupsStrAlloc(lineptr);
50ac8c
+      *string = strdup(lineptr);
50ac8c
 
50ac8c
       mask |= PPD_STRING;
50ac8c
     }
50ac8c
@@ -3384,7 +3330,7 @@ ppd_update_filters(ppd_file_t      *ppd,/* I - PPD file */
50ac8c
     filter           += ppd->num_filters;
50ac8c
     ppd->num_filters ++;
50ac8c
 
50ac8c
-    *filter = _cupsStrAlloc(buffer);
50ac8c
+    *filter = strdup(buffer);
50ac8c
   }
50ac8c
   while ((attr = ppdFindNextAttr(ppd, "cupsFilter2", NULL)) != NULL);
50ac8c
 
50ac8c
diff --git a/cups/ppd.h b/cups/ppd.h
50ac8c
index 3e281bd..340b7ca 100644
50ac8c
--- a/cups/ppd.h
50ac8c
+++ b/cups/ppd.h
50ac8c
@@ -315,8 +315,8 @@ typedef struct ppd_file_s		/**** PPD File ****/
50ac8c
   int		throughput;		/* Pages per minute */
50ac8c
   ppd_cs_t	colorspace;		/* Default colorspace */
50ac8c
   char		*patches;		/* Patch commands to be sent to printer */
50ac8c
-  int		num_emulations;		/* Number of emulations supported */
50ac8c
-  ppd_emul_t	*emulations;		/* Emulations and the code to invoke them */
50ac8c
+  int		num_emulations;		/* Number of emulations supported (no longer supported) @private@ */
50ac8c
+  ppd_emul_t	*emulations;		/* Emulations and the code to invoke them (no longer supported) @private@ */
50ac8c
   char		*jcl_begin;		/* Start JCL commands */
50ac8c
   char		*jcl_ps;		/* Enter PostScript interpreter */
50ac8c
   char		*jcl_end;		/* End JCL commands */
50ac8c
diff --git a/cups/string.c b/cups/string.c
50ac8c
index 538a263..bb148dd 100644
50ac8c
--- a/cups/string.c
50ac8c
+++ b/cups/string.c
50ac8c
@@ -303,6 +303,13 @@ _cupsStrFree(const char *s)		/* I - String to free */
50ac8c
 
50ac8c
   key = (_cups_sp_item_t *)(s - offsetof(_cups_sp_item_t, str));
50ac8c
 
50ac8c
+  if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, key)) != NULL &&
50ac8c
+      item == key)
50ac8c
+  {
50ac8c
+   /*
50ac8c
+    * Found it, dereference...
50ac8c
+    */
50ac8c
+
50ac8c
 #ifdef DEBUG_GUARDS
50ac8c
   if (key->guard != _CUPS_STR_GUARD)
50ac8c
   {
50ac8c
@@ -312,13 +319,6 @@ _cupsStrFree(const char *s)		/* I - String to free */
50ac8c
   }
50ac8c
 #endif /* DEBUG_GUARDS */
50ac8c
 
50ac8c
-  if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, key)) != NULL &&
50ac8c
-      item == key)
50ac8c
-  {
50ac8c
-   /*
50ac8c
-    * Found it, dereference...
50ac8c
-    */
50ac8c
-
50ac8c
     item->ref_count --;
50ac8c
 
50ac8c
     if (!item->ref_count)
50ac8c
diff --git a/ppdc/ppdc-import.cxx b/ppdc/ppdc-import.cxx
50ac8c
index d41cbb9..2999312 100644
50ac8c
--- a/ppdc/ppdc-import.cxx
50ac8c
+++ b/ppdc/ppdc-import.cxx
50ac8c
@@ -334,6 +334,9 @@ ppdcSource::import_ppd(const char *f)	// I - Filename
50ac8c
     }
50ac8c
   }
50ac8c
 
50ac8c
+  if (ppd)
50ac8c
+    ppdClose(ppd);
50ac8c
+
50ac8c
   return (1);
50ac8c
 }
50ac8c
 
50ac8c
diff --git a/scheduler/ipp.c b/scheduler/ipp.c
50ac8c
index 767ed25..207ebe7 100644
50ac8c
--- a/scheduler/ipp.c
50ac8c
+++ b/scheduler/ipp.c
50ac8c
@@ -2859,8 +2859,7 @@ add_printer(cupsd_client_t  *con,	/* I - Client connection */
50ac8c
       if (!strcmp(attr->values[i].string.text, "none"))
50ac8c
         continue;
50ac8c
 
50ac8c
-      printer->reasons[printer->num_reasons] =
50ac8c
-          _cupsStrRetain(attr->values[i].string.text);
50ac8c
+      printer->reasons[printer->num_reasons] = _cupsStrAlloc(attr->values[i].string.text);
50ac8c
       printer->num_reasons ++;
50ac8c
 
50ac8c
       if (!strcmp(attr->values[i].string.text, "paused") &&
50ac8c
@@ -5310,8 +5309,7 @@ copy_printer_attrs(
50ac8c
 
50ac8c
         if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported",
50ac8c
 	                               IPP_TAG_URI)) != NULL)
50ac8c
-          member_uris->values[i].string.text =
50ac8c
-	      _cupsStrRetain(p2_uri->values[0].string.text);
50ac8c
+          member_uris->values[i].string.text = _cupsStrAlloc(p2_uri->values[0].string.text);
50ac8c
         else
50ac8c
 	{
50ac8c
 	  httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri,
50ac8c
diff --git a/scheduler/printers.c b/scheduler/printers.c
50ac8c
index 2484db6..91cbc74 100644
50ac8c
--- a/scheduler/printers.c
50ac8c
+++ b/scheduler/printers.c
50ac8c
@@ -100,8 +100,7 @@ static void	delete_printer_filters(cupsd_printer_t *p);
50ac8c
 static void	dirty_printer(cupsd_printer_t *p);
50ac8c
 static void	load_ppd(cupsd_printer_t *p);
50ac8c
 static void	log_ipp_conformance(cupsd_printer_t *p, const char *reason);
50ac8c
-static ipp_t	*new_media_col(_pwg_size_t *size, const char *source,
50ac8c
-		               const char *type);
50ac8c
+static ipp_t	*new_media_col(_pwg_size_t *size);
50ac8c
 #ifdef __sgi
50ac8c
 static void	write_irix_config(cupsd_printer_t *p);
50ac8c
 static void	write_irix_state(cupsd_printer_t *p);
50ac8c
@@ -2219,7 +2218,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
50ac8c
     for (i = 0, name = (char *)cupsArrayFirst(p->users);
50ac8c
          name;
50ac8c
 	 i ++, name = (char *)cupsArrayNext(p->users))
50ac8c
-      attr->values[i].string.text = _cupsStrRetain(name);
50ac8c
+      attr->values[i].string.text = _cupsStrAlloc(name);
50ac8c
   }
50ac8c
 
50ac8c
   ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
@@ -2325,7 +2324,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
50ac8c
       for (i = 0; i < p->num_printers; i ++)
50ac8c
       {
50ac8c
 	if (attr != NULL)
50ac8c
-	  attr->values[i].string.text = _cupsStrRetain(p->printers[i]->name);
50ac8c
+	  attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->name);
50ac8c
 
50ac8c
 	p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
50ac8c
       }
50ac8c
@@ -2425,7 +2424,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
50ac8c
       {
50ac8c
 	for (i = 0; i < oldattr->num_values; i ++)
50ac8c
 	  attr->values[i].string.text =
50ac8c
-	      _cupsStrRetain(oldattr->values[i].string.text);
50ac8c
+	      _cupsStrAlloc(oldattr->values[i].string.text);
50ac8c
       }
50ac8c
     }
50ac8c
 
50ac8c
@@ -2479,7 +2478,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
50ac8c
       {
50ac8c
 	for (i = 0; i < oldattr->num_values; i ++)
50ac8c
 	  attr->values[i].string.text =
50ac8c
-	      _cupsStrRetain(oldattr->values[i].string.text);
50ac8c
+	      _cupsStrAlloc(oldattr->values[i].string.text);
50ac8c
       }
50ac8c
     }
50ac8c
 
50ac8c
@@ -2492,7 +2491,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
50ac8c
       {
50ac8c
 	for (i = 0; i < oldattr->num_values; i ++)
50ac8c
 	  attr->values[i].string.text =
50ac8c
-	      _cupsStrRetain(oldattr->values[i].string.text);
50ac8c
+	      _cupsStrAlloc(oldattr->values[i].string.text);
50ac8c
       }
50ac8c
     }
50ac8c
 
50ac8c
@@ -3799,21 +3798,19 @@ dirty_printer(cupsd_printer_t *p)	/* I - Printer */
50ac8c
 static void
50ac8c
 load_ppd(cupsd_printer_t *p)		/* I - Printer */
50ac8c
 {
50ac8c
-  int		i, j, k;		/* Looping vars */
50ac8c
+  int		i, j;		        /* Looping vars */
50ac8c
   char		cache_name[1024];	/* Cache filename */
50ac8c
   struct stat	cache_info;		/* Cache file info */
50ac8c
   ppd_file_t	*ppd;			/* PPD file */
50ac8c
   char		ppd_name[1024];		/* PPD filename */
50ac8c
   struct stat	ppd_info;		/* PPD file info */
50ac8c
-  int		num_media;		/* Number of media options */
50ac8c
+  int		num_media;		/* Number of media values */
50ac8c
   ppd_size_t	*size;			/* Current PPD size */
50ac8c
   ppd_option_t	*duplex,		/* Duplex option */
50ac8c
 		*output_bin,		/* OutputBin option */
50ac8c
 		*output_mode,		/* OutputMode option */
50ac8c
 		*resolution;		/* (Set|JCL|)Resolution option */
50ac8c
-  ppd_choice_t	*choice,		/* Current PPD choice */
50ac8c
-		*input_slot,		/* Current input slot */
50ac8c
-		*media_type;		/* Current media type */
50ac8c
+  ppd_choice_t	*choice;		/* Current PPD choice */
50ac8c
   ppd_attr_t	*ppd_attr;		/* PPD attribute */
50ac8c
   int		xdpi,			/* Horizontal resolution */
50ac8c
 		ydpi;			/* Vertical resolution */
50ac8c
@@ -4037,18 +4034,7 @@ load_ppd(cupsd_printer_t *p)		/* I - Printer */
50ac8c
       {
50ac8c
         ipp_t	*col;			/* Collection value */
50ac8c
 
50ac8c
-	input_slot = ppdFindMarkedChoice(ppd, "InputSlot");
50ac8c
-	media_type = ppdFindMarkedChoice(ppd, "MediaType");
50ac8c
-	col        = new_media_col(pwgsize,
50ac8c
-			           input_slot ?
50ac8c
-				       _ppdCacheGetSource(p->pc,
50ac8c
-				                          input_slot->choice) :
50ac8c
-				       NULL,
50ac8c
-				   media_type ?
50ac8c
-				       _ppdCacheGetType(p->pc,
50ac8c
-				                        media_type->choice) :
50ac8c
-				       NULL);
50ac8c
-
50ac8c
+	col = new_media_col(pwgsize);
50ac8c
 	ippAddCollection(p->ppd_attrs, IPP_TAG_PRINTER, "media-col-default",
50ac8c
 	                 col);
50ac8c
         ippDelete(col);
50ac8c
@@ -4071,13 +4057,13 @@ load_ppd(cupsd_printer_t *p)		/* I - Printer */
50ac8c
         for (i = p->pc->num_sizes, pwgsize = p->pc->sizes;
50ac8c
 	     i > 0;
50ac8c
 	     i --, pwgsize ++, val ++)
50ac8c
-	  val->string.text = _cupsStrRetain(pwgsize->map.pwg);
50ac8c
+	  val->string.text = _cupsStrAlloc(pwgsize->map.pwg);
50ac8c
 
50ac8c
         if (p->pc->custom_min_keyword)
50ac8c
 	{
50ac8c
-	  val->string.text = _cupsStrRetain(p->pc->custom_min_keyword);
50ac8c
+	  val->string.text = _cupsStrAlloc(p->pc->custom_min_keyword);
50ac8c
 	  val ++;
50ac8c
-	  val->string.text = _cupsStrRetain(p->pc->custom_max_keyword);
50ac8c
+	  val->string.text = _cupsStrAlloc(p->pc->custom_max_keyword);
50ac8c
         }
50ac8c
       }
50ac8c
 
50ac8c
@@ -4129,7 +4115,7 @@ load_ppd(cupsd_printer_t *p)		/* I - Printer */
50ac8c
 	         val = attr->values;
50ac8c
 	     i > 0;
50ac8c
 	     i --, pwgsource ++, val ++)
50ac8c
-	  val->string.text = _cupsStrRetain(pwgsource->pwg);
50ac8c
+	  val->string.text = _cupsStrAlloc(pwgsource->pwg);
50ac8c
       }
50ac8c
 
50ac8c
      /*
50ac8c
@@ -4145,7 +4131,7 @@ load_ppd(cupsd_printer_t *p)		/* I - Printer */
50ac8c
 	         val = attr->values;
50ac8c
 	     i > 0;
50ac8c
 	     i --, pwgtype ++, val ++)
50ac8c
-	  val->string.text = _cupsStrRetain(pwgtype->pwg);
50ac8c
+	  val->string.text = _cupsStrAlloc(pwgtype->pwg);
50ac8c
       }
50ac8c
 
50ac8c
      /*
50ac8c
@@ -4244,89 +4230,19 @@ load_ppd(cupsd_printer_t *p)		/* I - Printer */
50ac8c
       * media-col-database
50ac8c
       */
50ac8c
 
50ac8c
-      num_media = p->pc->num_sizes;
50ac8c
-      if (p->pc->num_sources)
50ac8c
+      if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER, "media-col-database", p->pc->num_sizes, NULL)) != NULL)
50ac8c
       {
50ac8c
-        if (p->pc->num_types > 0)
50ac8c
-	  num_media += p->pc->num_sizes * p->pc->num_sources *
50ac8c
-	               p->pc->num_types;
50ac8c
-	else
50ac8c
-          num_media += p->pc->num_sizes * p->pc->num_sources;
50ac8c
-      }
50ac8c
-      else if (p->pc->num_types)
50ac8c
-        num_media += p->pc->num_sizes * p->pc->num_types;
50ac8c
+       /*
50ac8c
+	* Add each page size without source or type...
50ac8c
+	*/
50ac8c
 
50ac8c
-      if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER,
50ac8c
-                                    "media-col-database", num_media,
50ac8c
-				    NULL)) != NULL)
50ac8c
-      {
50ac8c
-        for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, val = attr->values;
50ac8c
-	     i > 0;
50ac8c
-	     i --, pwgsize ++)
50ac8c
+        for (i = 0, pwgsize = p->pc->sizes; i < p->pc->num_sizes; i ++, pwgsize ++)
50ac8c
 	{
50ac8c
-	 /*
50ac8c
-	  * Start by adding the page size without source or type...
50ac8c
-	  */
50ac8c
+	  ipp_t *col = new_media_col(pwgsize);
50ac8c
 
50ac8c
-	  ppdMarkOption(ppd, "PageSize", pwgsize->map.ppd);
50ac8c
-
50ac8c
-          val->collection = new_media_col(pwgsize, NULL, NULL);
50ac8c
-	  val ++;
50ac8c
-
50ac8c
-         /*
50ac8c
-	  * Then add the specific, supported combinations of size, source, and
50ac8c
-	  * type...
50ac8c
-	  */
50ac8c
-
50ac8c
-	  if (p->pc->num_sources > 0)
50ac8c
-	  {
50ac8c
-	    for (j = p->pc->num_sources, pwgsource = p->pc->sources;
50ac8c
-	         j > 0;
50ac8c
-		 j --, pwgsource ++)
50ac8c
-	    {
50ac8c
-	      ppdMarkOption(ppd, "InputSlot", pwgsource->ppd);
50ac8c
-
50ac8c
-	      if (p->pc->num_types > 0)
50ac8c
-	      {
50ac8c
-	        for (k = p->pc->num_types, pwgtype = p->pc->types;
50ac8c
-		     k > 0;
50ac8c
-		     k --, pwgtype ++)
50ac8c
-		{
50ac8c
-		  if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd))
50ac8c
-		  {
50ac8c
-		    val->collection = new_media_col(pwgsize, pwgsource->pwg,
50ac8c
-		                                    pwgtype->pwg);
50ac8c
-		    val ++;
50ac8c
-		  }
50ac8c
-		}
50ac8c
-	      }
50ac8c
-	      else if (!ppdConflicts(ppd))
50ac8c
-	      {
50ac8c
-	        val->collection = new_media_col(pwgsize, pwgsource->pwg, NULL);
50ac8c
-		val ++;
50ac8c
-	      }
50ac8c
-	    }
50ac8c
-	  }
50ac8c
-	  else if (p->pc->num_types > 0)
50ac8c
-	  {
50ac8c
-	    for (j = p->pc->num_types, pwgtype = p->pc->types;
50ac8c
-	         j > 0;
50ac8c
-		 j --, pwgtype ++)
50ac8c
-	    {
50ac8c
-	      if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd))
50ac8c
-	      {
50ac8c
-	        val->collection = new_media_col(pwgsize, NULL, pwgtype->pwg);
50ac8c
-		val ++;
50ac8c
-	      }
50ac8c
-	    }
50ac8c
-	  }
50ac8c
+	  ippSetCollection(p->ppd_attrs, &attr, i, col);
50ac8c
+	  ippDelete(col);
50ac8c
 	}
50ac8c
-
50ac8c
-       /*
50ac8c
-        * Update the number of media-col-database values...
50ac8c
-	*/
50ac8c
-
50ac8c
-	attr->num_values = val - attr->values;
50ac8c
       }
50ac8c
     }
50ac8c
 
50ac8c
@@ -5081,9 +4997,7 @@ log_ipp_conformance(
50ac8c
  */
50ac8c
 
50ac8c
 static ipp_t *				/* O - Collection value */
50ac8c
-new_media_col(_pwg_size_t *size,	/* I - media-size/margin values */
50ac8c
-              const char  *source,	/* I - media-source value */
50ac8c
-              const char  *type)	/* I - media-type value */
50ac8c
+new_media_col(_pwg_size_t *size)	/* I - media-size/margin values */
50ac8c
 {
50ac8c
   ipp_t	*media_col,			/* Collection value */
50ac8c
 	*media_size;			/* media-size value */
50ac8c
@@ -5092,29 +5006,15 @@ new_media_col(_pwg_size_t *size,	/* I - media-size/margin values */
50ac8c
   media_col = ippNew();
50ac8c
 
50ac8c
   media_size = ippNew();
50ac8c
-  ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
-		"x-dimension", size->width);
50ac8c
-  ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
-		"y-dimension", size->length);
50ac8c
+  ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "x-dimension", size->width);
50ac8c
+  ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "y-dimension", size->length);
50ac8c
   ippAddCollection(media_col, IPP_TAG_PRINTER, "media-size", media_size);
50ac8c
   ippDelete(media_size);
50ac8c
 
50ac8c
-  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
-		"media-bottom-margin", size->bottom);
50ac8c
-  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
-		"media-left-margin", size->left);
50ac8c
-  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
-		"media-right-margin", size->right);
50ac8c
-  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
50ac8c
-		"media-top-margin", size->top);
50ac8c
-
50ac8c
-  if (source)
50ac8c
-    ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-source",
50ac8c
-		 NULL, source);
50ac8c
-
50ac8c
-  if (type)
50ac8c
-    ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-type",
50ac8c
-		 NULL, type);
50ac8c
+  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-bottom-margin", size->bottom);
50ac8c
+  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-left-margin", size->left);
50ac8c
+  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-right-margin", size->right);
50ac8c
+  ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-top-margin", size->top);
50ac8c
 
50ac8c
   return (media_col);
50ac8c
 }