changeset 32712:6ff3cc81d602

Fix resource leaks and check for realloc failures (reported by cppcheck)
author ib
date Wed, 19 Jan 2011 22:02:58 +0000
parents ebb1c06a639d
children f49e1b37281a
files gui/bitmap.c gui/interface.c gui/mplayer/gtk/pl.c gui/skin/font.c
diffstat 4 files changed, 37 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/gui/bitmap.c	Wed Jan 19 17:42:15 2011 +0000
+++ b/gui/bitmap.c	Wed Jan 19 22:02:58 2011 +0000
@@ -45,7 +45,11 @@
 
  fseek(fp, 0, SEEK_END);
  len = ftell(fp);
- if (len > 50 * 1024 * 1024) return 2;
+ if (len > 50 * 1024 * 1024)
+  {
+   fclose(fp);
+   return 2;
+  }
  data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
  fseek(fp, 0, SEEK_SET);
  fread(data, len, 1, fp);
--- a/gui/interface.c	Wed Jan 19 17:42:15 2011 +0000
+++ b/gui/interface.c	Wed Jan 19 22:02:58 2011 +0000
@@ -441,14 +441,24 @@
 
 static void add_vf( char * str )
 {
- mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_AddingVideoFilter,str );
+ void *p;
+
  if ( vf_settings )
   {
    int i = 0;
    while ( vf_settings[i].name ) if ( !gstrcmp( vf_settings[i++].name,str ) ) { i=-1; break; }
    if ( i != -1 )
-     { vf_settings=realloc( vf_settings,( i + 2 ) * sizeof( m_obj_settings_t ) ); vf_settings[i].name=strdup( str );vf_settings[i].attribs = NULL; vf_settings[i+1].name=NULL; }
-  } else { vf_settings=malloc( 2 * sizeof(  m_obj_settings_t ) ); vf_settings[0].name=strdup( str );vf_settings[0].attribs = NULL; vf_settings[1].name=NULL; }
+    {
+     if ( !( p=realloc( vf_settings,( i + 2 ) * sizeof( m_obj_settings_t ) ) ) ) return;
+     vf_settings=p;
+     vf_settings[i].name=strdup( str );
+     vf_settings[i].attribs = NULL;
+     vf_settings[i+1].name=NULL;
+    }
+  }
+ else { vf_settings=malloc( 2 * sizeof(  m_obj_settings_t ) ); vf_settings[0].name=strdup( str );vf_settings[0].attribs = NULL; vf_settings[1].name=NULL; }
+
+ mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_AddingVideoFilter,str );
 }
 
 static void remove_vf( char * str )
--- a/gui/mplayer/gtk/pl.c	Wed Jan 19 17:42:15 2011 +0000
+++ b/gui/mplayer/gtk/pl.c	Wed Jan 19 22:02:58 2011 +0000
@@ -283,6 +283,7 @@
   case 3: // add
        {
         int i;
+        void *p;
         char * itext[1][2];
         gchar * cpath;
         char * text[1][3]; text[0][2]="";
@@ -291,14 +292,19 @@
          {
           if ( CLFileSelected[i] )
            {
-	    gtk_clist_get_text( GTK_CLIST( CLFiles ),i,0,(char **)&itext );
-	    cpath=g_filename_to_utf8( current_path, -1, NULL, NULL, NULL );
-	    text[0][0]=itext[0][0]; text[0][1]=cpath;
-	    gtk_clist_append( GTK_CLIST( CLSelected ),text[0] );
-	    g_free( cpath );
 	    NrOfSelected++;
-	    CLListSelected=realloc( CLListSelected,NrOfSelected * sizeof( int ) );
-	    CLListSelected[NrOfSelected - 1]=0;
+	    p=realloc( CLListSelected,NrOfSelected * sizeof( int ) );
+	    if ( !p ) NrOfSelected--;
+	    else
+	     {
+	      CLListSelected=p;
+	      CLListSelected[NrOfSelected - 1]=0;
+	      gtk_clist_get_text( GTK_CLIST( CLFiles ),i,0,(char **)&itext );
+	      cpath=g_filename_to_utf8( current_path, -1, NULL, NULL, NULL );
+	      text[0][0]=itext[0][0]; text[0][1]=cpath;
+	      gtk_clist_append( GTK_CLIST( CLSelected ),text[0] );
+	      g_free( cpath );
+	     }
 	   }
 	 }
 	gtk_clist_thaw( GTK_CLIST( CLSelected ) );
--- a/gui/skin/font.c	Wed Jan 19 17:42:15 2011 +0000
+++ b/gui/skin/font.c	Wed Jan 19 22:02:58 2011 +0000
@@ -115,11 +115,16 @@
        {
         av_strlcpy( tmp,path,sizeof( tmp )  ); av_strlcat( tmp,param,sizeof( tmp ) );
         mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] font imagefile: %s\n",tmp );
-        if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) ) return -4;
+        if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) )
+         {
+          fclose(f);
+          return -4;
+         }
        }
      }
    }
 
+ fclose(f);
  return 0;
 }