[cups-filters] fix resource leaks and other problems found by Coverity & Valgrind (#959682)

Jiří Popelka jpopelka at fedoraproject.org
Mon Jun 3 09:34:36 UTC 2013


commit 245ec3a2aabc5f18f881dde894dad5d22af5c381
Author: Jiri Popelka <jpopelka at redhat.com>
Date:   Mon Jun 3 11:23:55 2013 +0200

    fix resource leaks and other problems found by Coverity & Valgrind (#959682)

 cups-filters-coverity.patch |  155 +++++++++++++++++++++++++++++++++++++++++++
 cups-filters-pcl.patch      |    6 +-
 cups-filters.spec           |    7 ++-
 3 files changed, 165 insertions(+), 3 deletions(-)
---
diff --git a/cups-filters-coverity.patch b/cups-filters-coverity.patch
new file mode 100644
index 0000000..9b5558f
--- /dev/null
+++ b/cups-filters-coverity.patch
@@ -0,0 +1,155 @@
+diff -up cups-filters-1.0.34/cupsfilters/image-tiff.c.coverity cups-filters-1.0.34/cupsfilters/image-tiff.c
+--- cups-filters-1.0.34/cupsfilters/image-tiff.c.coverity	2012-06-22 18:10:47.000000000 +0200
++++ cups-filters-1.0.34/cupsfilters/image-tiff.c	2013-06-03 11:09:53.138129637 +0200
+@@ -655,7 +655,12 @@ _cupsImageReadTIFF(
+     case PHOTOMETRIC_PALETTE :
+ 	if (!TIFFGetField(tif, TIFFTAG_COLORMAP, &redcmap, &greencmap, &bluecmap))
+ 	{
+-          fputs("DEBUG: No colormap tag in the file!\n", stderr);
++	  _TIFFfree(scanline);
++	  free(in);
++	  free(out);
++
++	  TIFFClose(tif);
++	  fputs("DEBUG: No colormap tag in the file!\n", stderr);
+ 	  fclose(fp);
+ 	  return (-1);
+ 	}
+diff -up cups-filters-1.0.34/filter/pdftopdf/nup.cc.coverity cups-filters-1.0.34/filter/pdftopdf/nup.cc
+--- cups-filters-1.0.34/filter/pdftopdf/nup.cc.coverity	2012-08-20 02:29:46.000000000 +0200
++++ cups-filters-1.0.34/filter/pdftopdf/nup.cc	2013-06-03 11:10:48.395383435 +0200
+@@ -52,7 +52,7 @@ bool NupParameters::possible(int nup) //
+ {
+   // 1 2 3 4 6 8 9 10 12 15 16
+   return (nup>=1)&&(nup<=16)&&
+-         ( (nup!=5)||(nup!=7)||(nup!=11)||(nup!=13)||(nup!=14) );
++         ( (nup!=5)&&(nup!=7)&&(nup!=11)&&(nup!=13)&&(nup!=14) );
+ }
+ // }}}
+ 
+diff -up cups-filters-1.0.34/filter/textcommon.c.coverity cups-filters-1.0.34/filter/textcommon.c
+--- cups-filters-1.0.34/filter/textcommon.c.coverity	2012-06-22 18:10:47.000000000 +0200
++++ cups-filters-1.0.34/filter/textcommon.c	2013-06-03 11:12:35.562934632 +0200
+@@ -608,6 +608,8 @@ TextMain(const char *name,	/* I - Name o
+ 
+     if (PageColumns < 1)
+     {
++      if (fp != stdin)
++        fclose(fp);
+       fprintf(stderr, "ERROR: Bad columns value %d.\n", PageColumns);
+       return (1);
+     }
+@@ -619,6 +621,8 @@ TextMain(const char *name,	/* I - Name o
+ 
+     if (CharsPerInch <= 0.0)
+     {
++      if (fp != stdin)
++        fclose(fp);
+       fprintf(stderr, "ERROR: Bad cpi value %f.\n", CharsPerInch);
+       return (1);
+     }
+@@ -630,6 +634,8 @@ TextMain(const char *name,	/* I - Name o
+ 
+     if (LinesPerInch <= 0.0)
+     {
++      if (fp != stdin)
++        fclose(fp);
+       fprintf(stderr, "ERROR: Bad lpi value %f.", LinesPerInch);
+       return (1);
+     }
+@@ -1110,6 +1116,9 @@ TextMain(const char *name,	/* I - Name o
+ 
+   WriteEpilogue();
+ 
++  if (fp != stdin)
++    fclose(fp);
++
+   if (ppd != NULL)
+     ppdClose(ppd);
+ 
+diff -up cups-filters-1.0.34/filter/texttopdf.c.coverity cups-filters-1.0.34/filter/texttopdf.c
+--- cups-filters-1.0.34/filter/texttopdf.c.coverity	2013-03-01 19:06:58.000000000 +0100
++++ cups-filters-1.0.34/filter/texttopdf.c	2013-06-03 11:13:22.533299254 +0200
+@@ -1220,6 +1220,7 @@ static void write_pretty_header() // {{{
+       x = PageRight - PageLeft - 36.0f / LinesPerInch - stringwidth_x(pagestr);
+   }
+   write_font_str(x,y,ATTR_BOLD,pagestr,-1);
++  free(pagestr);
+ 
+   pdfOut_printf(pdf,"Q\n");
+ }
+diff -up cups-filters-1.0.34/fontembed/embed_sfnt.c.coverity cups-filters-1.0.34/fontembed/embed_sfnt.c
+--- cups-filters-1.0.34/fontembed/embed_sfnt.c.coverity	2012-06-22 18:10:47.000000000 +0200
++++ cups-filters-1.0.34/fontembed/embed_sfnt.c	2013-06-03 11:14:09.803659682 +0200
+@@ -335,7 +335,7 @@ static const char *emb_otf_get_post_name
+     if (gid<num_glyphs) {
+       unsigned short idx=get_USHORT(post+34+2*gid);
+       if (idx<258) {
+-        if (gid<sizeof(macRoman)/sizeof(macRoman[0])) {
++        if (idx<sizeof(macRoman)/sizeof(macRoman[0])) {
+           return macRoman[idx];
+         } 
+       } else if (idx<32768) {
+diff -up cups-filters-1.0.34/utils/cups-browsed.c.coverity cups-filters-1.0.34/utils/cups-browsed.c
+--- cups-filters-1.0.34/utils/cups-browsed.c.coverity	2013-04-10 17:37:14.000000000 +0200
++++ cups-filters-1.0.34/utils/cups-browsed.c	2013-06-03 11:16:45.768548935 +0200
+@@ -403,6 +403,8 @@ gboolean handle_cups_queues(gpointer unu
+ 	  p->timeout = current_time + TIMEOUT_RETRY;
+ 	  break;
+ 	}
++	if (response)
++	  ippDelete(response);
+ 
+ 	/* No jobs, not default printer, remove the CUPS queue */
+ 	request = ippNewRequest(CUPS_DELETE_PRINTER);
+@@ -635,6 +637,8 @@ void generate_local_queue(const char *ho
+ 	   ignore this remote printer */
+ 	debug_printf("cups-browsed: %s also taken, printer ignored.\n",
+ 		     local_queue_name);
++	free (backup_queue_name);
++	free (remote_host);
+ 	return;
+       }
+     }
+@@ -716,6 +720,8 @@ void generate_local_queue(const char *ho
+ 			    name ? name : "", type, domain);
+     free (uri);
+   }
++  free (backup_queue_name);
++  free (remote_host);
+ 
+   if (p)
+     debug_printf("cups-browsed: Bonjour IDs: Service name: \"%s\", "
+@@ -1562,8 +1568,11 @@ fail:
+   if (conn)
+     httpClose (conn);
+ 
++  if (server)
++    free (server);
++
+   /* Call a new timeout handler so that we run again */
+-  g_timeout_add_seconds (BrowseInterval, browse_poll, server);
++  g_timeout_add_seconds (BrowseInterval, browse_poll, data);
+ 
+   /* Stop this timeout handler, we called a new one */
+   return FALSE;
+@@ -1933,13 +1942,13 @@ int main(int argc, char*argv[]) {
+   }
+ 
+   if (BrowsePoll) {
+-    char **server;
+-    for (server = BrowsePoll;
+-	 *server;
+-	 server++) {
++    size_t index;
++    for (index = 0;
++	 index < NumBrowsePoll;
++	 index++) {
+       debug_printf ("cups-browsed: will browse poll %s every %ds\n",
+-		    *server, BrowseInterval);
+-      g_idle_add (browse_poll, *server);
++		    BrowsePoll[index], BrowseInterval);
++      g_idle_add (browse_poll, BrowsePoll[index]);
+     }
+   }
+ 
diff --git a/cups-filters-pcl.patch b/cups-filters-pcl.patch
index 3cc4e54..115b36e 100644
--- a/cups-filters-pcl.patch
+++ b/cups-filters-pcl.patch
@@ -1,7 +1,7 @@
 diff -up cups-filters-1.0.34/Makefile.am.pcl cups-filters-1.0.34/Makefile.am
 --- cups-filters-1.0.34/Makefile.am.pcl	2013-03-19 16:19:30.000000000 +0100
-+++ cups-filters-1.0.34/Makefile.am	2013-05-15 11:57:00.068339837 +0200
-@@ -213,6 +213,13 @@ pkgdriver_DATA = \
++++ cups-filters-1.0.34/Makefile.am	2013-05-15 15:33:37.094839315 +0200
+@@ -213,6 +213,15 @@ pkgdriver_DATA = \
  
  EXTRA_DIST += $(pkgdriver_DATA)
  
@@ -12,6 +12,8 @@ diff -up cups-filters-1.0.34/Makefile.am.pcl cups-filters-1.0.34/Makefile.am
 +pkgppdc_DATA = \
 +	filter/pcl.h
 +
++EXTRA_DIST += $(pkgppdc_DATA)
++
  # =====
  # MIMEs
  # =====
diff --git a/cups-filters.spec b/cups-filters.spec
index fb0394e..4ebb59a 100644
--- a/cups-filters.spec
+++ b/cups-filters.spec
@@ -4,7 +4,7 @@
 Summary: OpenPrinting CUPS filters and backends
 Name:    cups-filters
 Version: 1.0.34
-Release: 3%{?dist}
+Release: 4%{?dist}
 
 # For a breakdown of the licensing, see COPYING file
 # GPLv2:   filters: commandto*, imagetoraster, pdftops, rasterto*,
@@ -23,6 +23,7 @@ Source0: http://www.openprinting.org/download/cups-filters/cups-filters-%{versio
 Source1: cups-browsed.service
 
 Patch1: cups-filters-pcl.patch
+Patch2: cups-filters-coverity.patch
 
 Requires: cups-filters-libs%{?_isa} = %{version}-%{release}
 
@@ -93,6 +94,7 @@ This is the development package for OpenPrinting CUPS filters and backends.
 %prep
 %setup -q
 %patch1 -p1 -b .pcl
+%patch2 -p1 -b .coverity
 
 %build
 # work-around Rpath
@@ -200,6 +202,9 @@ fi
 %{_libdir}/libfontembed.so
 
 %changelog
+* Mon Jun 03 2013 Jiri Popelka <jpopelka at redhat.com> - 1.0.34-4
+- fix resource leaks and other problems found by Coverity & Valgrind (#959682)
+
 * Wed May 15 2013 Jiri Popelka <jpopelka at redhat.com> - 1.0.34-3
 - ship ppdc/pcl.h because of cupsfilters.drv
 


More information about the scm-commits mailing list