From 859436564cd0b85e76b888a88205424ede9cb412 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Duraffort?= Date: Wed, 12 Mar 2008 00:30:25 +0100 Subject: [PATCH] One more "Remove useless test before free" --- src/audio_output/input.c | 4 +-- src/control/vlm.c | 5 ++- src/libvlc-common.c | 14 ++++----- src/network/httpd.c | 48 +++++++++-------------------- src/stream_output/stream_output.c | 17 +++++----- src/video_output/video_output.c | 19 +++++------- src/video_output/vout_intf.c | 10 +++--- src/video_output/vout_subpictures.c | 18 +++++------ 8 files changed, 53 insertions(+), 82 deletions(-) diff --git a/src/audio_output/input.c b/src/audio_output/input.c index c233a6e2d5..1886b50dbd 100644 --- a/src/audio_output/input.c +++ b/src/audio_output/input.c @@ -349,8 +349,8 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input ) psz_parser = psz_next; } } - if( psz_filters ) free( psz_filters ); - if( psz_visual ) free( psz_visual ); + free( psz_filters ); + free( psz_visual ); /* complete the filter chain if necessary */ if ( !AOUT_FMTS_IDENTICAL( &chain_input_format, &chain_output_format ) ) diff --git a/src/control/vlm.c b/src/control/vlm.c index a5bd67bd83..0e794e4917 100644 --- a/src/control/vlm.c +++ b/src/control/vlm.c @@ -208,7 +208,7 @@ void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name, void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name, char *psz_output, libvlc_exception_t *p_exception ) { -#define VLM_CHANGE_CODE { if( p_media->psz_output ) free( p_media->psz_output ); \ +#define VLM_CHANGE_CODE { free( p_media->psz_output ); \ p_media->psz_output = strdup( psz_output ); } VLM_CHANGE( "Unable to change %s output property", VLM_CHANGE_CODE ); #undef VLM_CHANGE_CODE @@ -244,8 +244,7 @@ void libvlc_vlm_change_media( libvlc_instance_t *p_instance, char *psz_name, free( p_media->ppsz_input[--p_media->i_input] ); \ if( psz_input ) \ TAB_APPEND( p_media->i_input, p_media->ppsz_input, strdup(psz_input) ); \ - if( p_media->psz_output ) \ - free( p_media->psz_output ); \ + free( p_media->psz_output ); \ p_media->psz_output = psz_output ? strdup( psz_output ) : NULL; \ while( p_media->i_option > 0 ) \ free( p_media->ppsz_option[--p_media->i_option] ); \ diff --git a/src/libvlc-common.c b/src/libvlc-common.c index 11429446b9..9e33d92beb 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -420,7 +420,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE ); libvlc_global.p_module_bank->b_cache_delete = b_cache_delete; } - if( psz_language ) free( psz_language ); + free( psz_language ); # endif #endif @@ -752,7 +752,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, /* Add service discovery modules */ playlist_ServicesDiscoveryAdd( p_playlist, psz_modules ); } - if( psz_modules ) free( psz_modules ); + free( psz_modules ); /* * Load background interfaces @@ -856,12 +856,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, if( psz_morecodecs ) { config_PutPsz( p_libvlc, "codec", psz_morecodecs); - free(psz_morecodecs); + free( psz_morecodecs ); } } else config_PutPsz( p_libvlc, "codec", "dmo,quicktime"); - free(psz_codecs); + free( psz_codecs ); } #endif @@ -896,7 +896,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, VLC_AddTarget( p_libvlc->i_object_id, val.psz_string, NULL, 0, PLAYLIST_INSERT, 0 ); } - if ( val.psz_string != NULL ) free( val.psz_string ); + free( val.psz_string ); return VLC_SUCCESS; } @@ -991,7 +991,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release ) psz_pidfile ); } } - free ( psz_pidfile ); + free( psz_pidfile ); } #endif @@ -1072,7 +1072,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, * We prefer the dummy interface if none is specified. */ char *psz_interface = config_GetPsz( p_libvlc, "intf" ); if( !psz_interface || !*psz_interface ) psz_module = "dummy"; - if( psz_interface ) free( psz_interface ); + free( psz_interface ); } #endif diff --git a/src/network/httpd.c b/src/network/httpd.c index d8c86189ee..79f96f2590 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -897,11 +897,9 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host, int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data ) { vlc_mutex_lock( &stream->lock ); - if( stream->p_header ) - { - free( stream->p_header ); - stream->p_header = NULL; - } + free( stream->p_header ); + stream->p_header = NULL; + stream->i_header = i_data; if( i_data > 0 ) { @@ -953,9 +951,9 @@ void httpd_StreamDelete( httpd_stream_t *stream ) { httpd_UrlDelete( stream->url ); vlc_mutex_destroy( &stream->lock ); - if( stream->psz_mime ) free( stream->psz_mime ); - if( stream->p_header ) free( stream->p_header ); - if( stream->p_buffer ) free( stream->p_buffer ); + free( stream->psz_mime ); + free( stream->p_header ); + free( stream->p_buffer ); free( stream ); } @@ -1007,7 +1005,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname, httpd = (httpd_t *)vlc_custom_create( p_this, sizeof (*httpd), VLC_OBJECT_HTTPD, psz_object_type ); - if (httpd == NULL) + if( httpd == NULL ) { vlc_mutex_unlock( lockval.p_address ); free( psz_host ); @@ -1334,31 +1332,16 @@ void httpd_MsgClean( httpd_message_t *msg ) { int i; - if( msg->psz_url ) - { - free( msg->psz_url ); - } - if( msg->psz_args ) - { - free( msg->psz_args ); - } + free( msg->psz_url ); + free( msg->psz_args ); for( i = 0; i < msg->i_name; i++ ) { free( msg->name[i] ); free( msg->value[i] ); } - if( msg->name ) - { - free( msg->name ); - } - if( msg->value ) - { - free( msg->value ); - } - if( msg->p_body ) - { - free( msg->p_body ); - } + free( msg->name ); + free( msg->value ); + free( msg->p_body ); httpd_MsgInit( msg ); } @@ -1448,11 +1431,8 @@ static void httpd_ClientClean( httpd_client_t *cl ) httpd_MsgClean( &cl->answer ); httpd_MsgClean( &cl->query ); - if( cl->p_buffer ) - { - free( cl->p_buffer ); - cl->p_buffer = NULL; - } + free( cl->p_buffer ); + cl->p_buffer = NULL; } static httpd_client_t *httpd_ClientNew( int fd, tls_session_t *p_tls, mtime_t now ) diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c index 8489d8716d..81af00a674 100644 --- a/src/stream_output/stream_output.c +++ b/src/stream_output/stream_output.c @@ -307,10 +307,7 @@ sout_access_out_t *sout_AccessOutNew( sout_instance_t *p_sout, psz_next = config_ChainCreate( &p_access->psz_access, &p_access->p_cfg, psz_access ); - if( psz_next ) - { - free( psz_next ); - } + free( psz_next ); p_access->psz_path = strdup( psz_name ? psz_name : "" ); p_access->p_sout = p_sout; p_access->p_sys = NULL; @@ -419,7 +416,7 @@ sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux, p_mux->p_sout = p_sout; psz_next = config_ChainCreate( &p_mux->psz_mux, &p_mux->p_cfg, psz_mux ); - if( psz_next ) free( psz_next ); + free( psz_next ); p_mux->p_access = p_access; p_mux->pf_control = NULL; @@ -539,11 +536,11 @@ sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt ) TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); if( p_mux->pf_addstream( p_mux, p_input ) < 0 ) { - msg_Err( p_mux, "cannot add this stream" ); - TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); - block_FifoRelease( p_input->p_fifo ); - free( p_input ); - return NULL; + msg_Err( p_mux, "cannot add this stream" ); + TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); + block_FifoRelease( p_input->p_fifo ); + free( p_input ); + return NULL; } return p_input; diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c index 875e8bb900..e97cb57f25 100644 --- a/src/video_output/video_output.c +++ b/src/video_output/video_output.c @@ -177,12 +177,12 @@ vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout, var_Get( p_vout, "vout-filter", &val ); psz_filter_chain = val.psz_string; - if( psz_filter_chain && !*psz_filter_chain ) + if( !*psz_filter_chain ) { free( psz_filter_chain ); psz_filter_chain = NULL; } - if( p_vout->psz_filter_chain && !*p_vout->psz_filter_chain ) + if( !*p_vout->psz_filter_chain ) { free( p_vout->psz_filter_chain ); p_vout->psz_filter_chain = NULL; @@ -193,7 +193,7 @@ vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout, p_vout->b_filter_change = VLC_FALSE; } - if( psz_filter_chain ) free( psz_filter_chain ); + free( psz_filter_chain ); } if( ( p_vout->fmt_render.i_width != p_fmt->i_width ) || @@ -431,7 +431,7 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt ) if( var_Get( p_vout, "deinterlace-mode", &val ) == VLC_SUCCESS ) { var_Set( p_vout, "deinterlace", val ); - if( val.psz_string ) free( val.psz_string ); + free( val.psz_string ); } var_AddCallback( p_vout, "deinterlace", DeinterlaceCallback, NULL ); @@ -498,7 +498,7 @@ void vout_Destroy( vout_thread_t *p_vout ) var_Destroy( p_vout, "intf-change" ); - if( p_vout->psz_filter_chain ) free( p_vout->psz_filter_chain ); + free( p_vout->psz_filter_chain ); config_ChainDestroy( p_vout->p_cfg ); @@ -1505,7 +1505,7 @@ static int DeinterlaceCallback( vlc_object_t *p_this, char const *psz_cmd, val.psz_string = psz_filter; var_Set( p_vout, "vout-filter", val ); - if( psz_filter ) free( psz_filter ); + free( psz_filter ); return VLC_SUCCESS; } @@ -1564,11 +1564,8 @@ static int ParseVideoFilter2Chain( vout_thread_t *p_vout, char *psz_vfilters ) struct config_chain_t *p_cfg = p_vout->p_vfilters_cfg[p_vout->i_vfilters_cfg]; config_ChainDestroy( p_cfg ); - if( p_vout->psz_vfilters[p_vout->i_vfilters_cfg] ) - { - free( p_vout->psz_vfilters[p_vout->i_vfilters_cfg] ); - p_vout->psz_vfilters[p_vout->i_vfilters_cfg] = NULL; - } + free( p_vout->psz_vfilters[p_vout->i_vfilters_cfg] ); + p_vout->psz_vfilters[p_vout->i_vfilters_cfg] = NULL; } p_vout->i_vfilters_cfg = 0; if( psz_vfilters && *psz_vfilters ) diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c index 466b1c79a9..f210f5b57a 100644 --- a/src/video_output/vout_intf.c +++ b/src/video_output/vout_intf.c @@ -359,7 +359,7 @@ void vout_IntfInit( vout_thread_t *p_vout ) var_Get( p_vout, "crop", &old_val ); if( old_val.psz_string && *old_val.psz_string ) var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 ); - if( old_val.psz_string ) free( old_val.psz_string ); + free( old_val.psz_string ); /* Monitor pixel aspect-ratio */ var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); @@ -392,7 +392,7 @@ void vout_IntfInit( vout_thread_t *p_vout ) p_vout->i_par_num, p_vout->i_par_den ); b_force_par = VLC_TRUE; } - if( val.psz_string ) free( val.psz_string ); + free( val.psz_string ); /* Aspect-ratio object var */ var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND | @@ -420,7 +420,7 @@ void vout_IntfInit( vout_thread_t *p_vout ) var_Get( p_vout, "aspect-ratio", &old_val ); if( (old_val.psz_string && *old_val.psz_string) || b_force_par ) var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 ); - if( old_val.psz_string ) free( old_val.psz_string ); + free( old_val.psz_string ); /* Initialize the dimensions of the video window */ InitWindowSize( p_vout, &p_vout->i_window_width, @@ -481,7 +481,7 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic ) memset( &fmt_out, 0, sizeof(video_format_t) ); var_Get( p_vout, "snapshot-path", &val ); - if( val.psz_string && !*val.psz_string ) + if( !*val.psz_string ) { free( val.psz_string ); val.psz_string = 0; @@ -650,7 +650,7 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic ) var_Get( p_vout, "snapshot-format", &format ); if( !format.psz_string || !*format.psz_string ) { - if( format.psz_string ) free( format.psz_string ); + free( format.psz_string ); format.psz_string = strdup( "png" ); } diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c index 8e1f9ceaa7..6531492e1d 100644 --- a/src/video_output/vout_subpictures.c +++ b/src/video_output/vout_subpictures.c @@ -172,7 +172,7 @@ int spu_ParseChain( spu_t *p_spu ) free( psz_name ); } - if( val.psz_string ) free( val.psz_string ); + free( val.psz_string ); return VLC_SUCCESS; } @@ -280,7 +280,7 @@ void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, vlc_bool_t b_attach ) */ static void RegionPictureRelease( picture_t *p_pic ) { - if( p_pic->p_data_orig ) free( p_pic->p_data_orig ); + free( p_pic->p_data_orig ); } subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this, video_format_t *p_fmt ) @@ -310,7 +310,7 @@ subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this, if( !p_region->picture.i_planes ) { free( p_region ); - if( p_fmt->p_palette ) free( p_fmt->p_palette ); + free( p_fmt->p_palette ); return NULL; } @@ -362,13 +362,11 @@ void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region ) if( !p_region ) return; if( p_region->picture.pf_release ) p_region->picture.pf_release( &p_region->picture ); - if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette ); + free( p_region->fmt.p_palette ); if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache ); - if( p_region->psz_text ) - free( p_region->psz_text ); - if( p_region->psz_html ) - free( p_region->psz_html ); + free( p_region->psz_text ); + free( p_region->psz_html ); //free( p_region->p_style ); FIXME --fenrir plugin does not allocate the memory for it. I think it might lead to segfault, video renderer can live longer than the decoder free( p_region ); } @@ -626,7 +624,7 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt, p_spu->p_text->p_module = module_Need( p_spu->p_text, "text renderer", 0, 0 ); } - if( psz_modulename ) free( psz_modulename ); + free( psz_modulename ); } if( p_spu->p_text ) @@ -1385,7 +1383,7 @@ static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic ) (void)p_filter; if( p_pic ) { - if( p_pic->p_data_orig ) free( p_pic->p_data_orig ); + free( p_pic->p_data_orig ); free( p_pic ); } } -- 2.39.2