[MPlayer-cvslog] r32799 - in trunk/gui: bitmap.c interface.c mplayer/gtk/pl.c skin/font.c

ib subversion at mplayerhq.hu
Wed Jan 19 23:02:58 CET 2011


Author: ib
Date: Wed Jan 19 23:02:58 2011
New Revision: 32799

Log:
Fix resource leaks and check for realloc failures

(reported by cppcheck)

Modified:
   trunk/gui/bitmap.c
   trunk/gui/interface.c
   trunk/gui/mplayer/gtk/pl.c
   trunk/gui/skin/font.c

Modified: trunk/gui/bitmap.c
==============================================================================
--- trunk/gui/bitmap.c	Wed Jan 19 18:42:15 2011	(r32798)
+++ trunk/gui/bitmap.c	Wed Jan 19 23:02:58 2011	(r32799)
@@ -45,7 +45,11 @@ static int pngRead( unsigned char * fnam
 
  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);

Modified: trunk/gui/interface.c
==============================================================================
--- trunk/gui/interface.c	Wed Jan 19 18:42:15 2011	(r32798)
+++ trunk/gui/interface.c	Wed Jan 19 23:02:58 2011	(r32799)
@@ -441,14 +441,24 @@ void guiLoadSubtitle( char * name )
 
 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 )

Modified: trunk/gui/mplayer/gtk/pl.c
==============================================================================
--- trunk/gui/mplayer/gtk/pl.c	Wed Jan 19 18:42:15 2011	(r32798)
+++ trunk/gui/mplayer/gtk/pl.c	Wed Jan 19 23:02:58 2011	(r32799)
@@ -283,6 +283,7 @@ static void plButtonReleased( GtkButton 
   case 3: // add
        {
         int i;
+        void *p;
         char * itext[1][2];
         gchar * cpath;
         char * text[1][3]; text[0][2]="";
@@ -291,14 +292,19 @@ static void plButtonReleased( GtkButton 
          {
           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 ) );

Modified: trunk/gui/skin/font.c
==============================================================================
--- trunk/gui/skin/font.c	Wed Jan 19 18:42:15 2011	(r32798)
+++ trunk/gui/skin/font.c	Wed Jan 19 23:02:58 2011	(r32799)
@@ -115,11 +115,16 @@ int fntRead( char * path,char * fname )
        {
         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;
 }
 


More information about the MPlayer-cvslog mailing list