Mercurial > mplayer.hg
diff gui/interface.c @ 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 | 18338ee51c9d |
children | 12ae3b893c59 |
line wrap: on
line diff
--- 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 )