Index: tvtime-1.0.2/intl/localcharset.c
===================================================================
--- tvtime-1.0.2.orig/intl/localcharset.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/intl/localcharset.c	2013-06-15 13:04:54.919022684 +0000
@@ -145,6 +145,7 @@
 	  char buf1[50+1];
 	  char buf2[50+1];
 	  char *res_ptr = NULL;
+	  char *res_new, *res_ptr;
 	  size_t res_size = 0;
 	  size_t l1, l2;
 
@@ -178,14 +179,16 @@
 	      else
 		{
 		  res_size += l1 + 1 + l2 + 1;
-		  res_ptr = (char *) realloc (res_ptr, res_size + 1);
+		  res_new = (char *) realloc (res_ptr, res_size + 1);
 		}
-	      if (res_ptr == NULL)
+	      if (res_new == NULL)
 		{
 		  /* Out of memory. */
+		  free(res_ptr);
 		  res_size = 0;
 		  break;
 		}
+	      res_ptr = res_new;
 	      strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
 	      strcpy (res_ptr + res_size - (l2 + 1), buf2);
 	    }
Index: tvtime-1.0.2/intl/localealias.c
===================================================================
--- tvtime-1.0.2.orig/intl/localealias.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/intl/localealias.c	2013-06-15 13:04:54.919022684 +0000
@@ -303,7 +303,10 @@
 
 	      if (nmap >= maxmap)
 		if (__builtin_expect (extend_alias_table (), 0))
-		  return added;
+		  {
+                   fclose (fp);
+		    return added;
+		  }
 
 	      alias_len = strlen (alias) + 1;
 	      value_len = strlen (value) + 1;
@@ -316,7 +319,10 @@
 					? alias_len + value_len : 1024));
 		  char *new_pool = (char *) realloc (string_space, new_size);
 		  if (new_pool == NULL)
-		    return added;
+		    {
+                     fclose (fp);
+		      return added;
+		    }
 
 		  if (__builtin_expect (string_space != new_pool, 0))
 		    {
Index: tvtime-1.0.2/plugins/kdetv_greedyh.c
===================================================================
--- tvtime-1.0.2.orig/plugins/kdetv_greedyh.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/plugins/kdetv_greedyh.c	2013-06-15 13:04:54.919022684 +0000
@@ -40,7 +40,7 @@
                                           int width, int height )
 {
     TDeinterlaceInfo Info;
-    TPicture Picture[ 8 ];
+    TPicture Picture[ MAX_PICTURE_HISTORY ];
     int stride = (width*2);
     int i;
 
Index: tvtime-1.0.2/plugins/kdetv_tomsmocomp.c
===================================================================
--- tvtime-1.0.2.orig/plugins/kdetv_tomsmocomp.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/plugins/kdetv_tomsmocomp.c	2013-06-15 13:04:54.919022684 +0000
@@ -39,7 +39,7 @@
                                              int width, int height )
 {
     TDeinterlaceInfo Info;
-    TPicture Picture[ 8 ];
+    TPicture Picture[ MAX_PICTURE_HISTORY ];
     int stride = (width*2);
     int i;
 
Index: tvtime-1.0.2/src/commands.c
===================================================================
--- tvtime-1.0.2.orig/src/commands.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/src/commands.c	2013-06-15 13:04:54.923022684 +0000
@@ -2401,13 +2401,11 @@
     case TVTIME_SET_INPUT_WIDTH:
         cmd->newinputwidth = atoi( arg );
         if( cmd->osd ) {
-            const char *curname = menu_get_name( cmd->curusermenu );
             menu_t *sharpmenu = commands_get_menu( cmd, "hres" );
             char message[ 128 ];
             int maxw = cmd->vidin? videoinput_get_maxwidth( cmd->vidin ) : 0;
             reset_inputwidth_menu( sharpmenu, cmd->newinputwidth, maxw );
             curname = menu_get_name( cmd->curusermenu );
-            commands_refresh_menu( cmd );
             snprintf( message, sizeof( message ),
                       _("Horizontal resolution will be %d pixels on restart."),
                       cmd->newinputwidth );
Index: tvtime-1.0.2/src/leetft.c
===================================================================
--- tvtime-1.0.2.orig/src/leetft.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/src/leetft.c	2013-06-15 13:04:54.923022684 +0000
@@ -78,6 +78,7 @@
     error = FT_Load_Glyph( font->face, glyph_index, FT_LOAD_NO_HINTING );
     if( error ) {
         fprintf( stderr, "leetft: Can't load glyph %ld\n", (long int) wchar );
+        free ( cur );
         return 0;
     }
     
Index: tvtime-1.0.2/src/station.c
===================================================================
--- tvtime-1.0.2.orig/src/station.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/src/station.c	2013-06-15 13:04:54.923022684 +0000
@@ -1030,8 +1030,15 @@
 
     if( !rp ) return 0;
 
-    strncpy( filename, getenv( "HOME" ), 235 );
-    strncat( filename, "/.tvtime/stationlist.xml", 255 );
+    static const char config_filename[] = "/.tvtime/stationlist.xml";
+    const char *home = getenv( "HOME" );
+    size_t len = strlen( home );
+    if ( len > sizeof( filename ) - sizeof( config_filename ) )
+            fprintf( stderr, "station: Could not create new config file. The file name will be too long.\n" );
+    else {
+        memmove( filename, home, len );
+        memmove( filename + len, config_filename, sizeof( config_filename ) );
+    }
 
     doc = xmlParseFile( filename );
     if( !doc ) {
Index: tvtime-1.0.2/src/tvtime.c
===================================================================
--- tvtime-1.0.2.orig/src/tvtime.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/src/tvtime.c	2013-06-15 13:04:54.923022684 +0000
@@ -1301,6 +1301,7 @@
     perf = performance_new( fieldtime );
     if( !perf ) {
         lfprintf( stderr, _("%s: Cannot allocate memory.\n"), argv[ 0 ] );
+        free ( tvtime);
         return 1;
     }
 
@@ -1309,6 +1310,7 @@
                               config_get_ntsc_cable_mode( ct ), verbose );
     if( !stationmgr ) {
         lfprintf( stderr, _("%s: Cannot allocate memory.\n"), argv[ 0 ] );
+        free ( tvtime );
         return 1;
     }
     station_set( stationmgr, config_get_prev_channel( ct ) );
@@ -1365,6 +1367,7 @@
     /* Set input size. */
     if( !output->set_input_size( width, height ) ) {
         /* FIXME: Clean up. */
+        free ( tvtime );
         return 1;
     }
 
@@ -1432,6 +1435,11 @@
     blueframe = malloc( width * height * 2 );
     if( !colourbars || !saveframe || !fadeframe || !blueframe ) {
         lfprintf( stderr, _("%s: Cannot allocate memory.\n"), argv[ 0 ] );
+        free( colourbars );
+        free( saveframe );
+        free( fadeframe );
+        free( blueframe );
+        free( tvtime );
         return 1;
     }
     build_colourbars( colourbars, width, height );
@@ -2547,6 +2555,7 @@
      * file in "C" locale format.
      */
     strncpy( prevloc, setlocale( LC_NUMERIC, NULL ), sizeof( prevloc ) );
+    prevloc[ 255 ] = '\0';
     setlocale( LC_NUMERIC, "C" );
     snprintf( number, 4, "%2.1f",
               commands_get_overscan( commands ) * 2.0 * 100.0 );
Index: tvtime-1.0.2/src/tvtimeconf.c
===================================================================
--- tvtime-1.0.2.orig/src/tvtimeconf.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/src/tvtimeconf.c	2013-06-15 13:04:54.923022684 +0000
@@ -391,6 +391,7 @@
              * the config file in "C" locale format.
              */
             strncpy( prevloc, setlocale( LC_NUMERIC, NULL ), sizeof prevloc );
+            prevloc[ 255 ] = '\0';
             setlocale( LC_NUMERIC, "C" );
             ct->overscan = ( atof( curval ) / 2.0 ) / 100.0;
             if( !isnormal( ct->overscan ) ) {
@@ -983,6 +984,7 @@
         if( fifofd >= 0 ) {
             lfprintf( stderr,
                       _("Cannot run two instances of tvtime with the same configuration.\n") );
+            close( fifofd );
             return 0;
         }
         close( fifofd );
@@ -1182,6 +1184,7 @@
         if( fifofd >= 0 ) {
             lfprintf( stderr,
                       _("Cannot update configuration while tvtime running.\n") );
+            close( fifofd );
             return 0;
         }
         close( fifofd );
Index: tvtime-1.0.2/src/utils.c
===================================================================
--- tvtime-1.0.2.orig/src/utils.c	2013-06-15 13:04:54.927022684 +0000
+++ tvtime-1.0.2/src/utils.c	2013-06-15 13:04:54.923022684 +0000
@@ -127,6 +127,7 @@
                 closedir( temp_dir );
                 return 1;
             }
+            closedir( temp_dir );
         }
     } else {
         /* We created the directory, now force it to be owned by the user. */
