From 7eaca895c90b3f14ab208373d0213d0579515e70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Duraffort?= Date: Thu, 22 May 2008 21:58:28 +0200 Subject: [PATCH] Check malloc return value when needed and don't print an error when such error happend. Fix a potential segfault. --- modules/video_output/aa.c | 3 --- modules/video_output/caca.c | 3 --- modules/video_output/directfb.c | 3 --- modules/video_output/fb.c | 5 ----- modules/video_output/ggi.c | 3 --- modules/video_output/glide.c | 3 --- modules/video_output/hd1000v.cpp | 5 +---- modules/video_output/image.c | 3 +++ modules/video_output/mga.c | 3 --- modules/video_output/msw/direct3d.c | 3 --- modules/video_output/msw/directx.c | 3 --- modules/video_output/msw/events.c | 9 ++++++--- modules/video_output/msw/glwin32.c | 3 --- modules/video_output/opengl.c | 11 +---------- modules/video_output/qte/qte.cpp | 3 --- modules/video_output/x11/xcommon.c | 6 ------ 16 files changed, 11 insertions(+), 58 deletions(-) diff --git a/modules/video_output/aa.c b/modules/video_output/aa.c index 00b88f202f..92e663c76c 100644 --- a/modules/video_output/aa.c +++ b/modules/video_output/aa.c @@ -90,10 +90,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return( 1 ); - } /* Don't parse any options, but take $AAOPTS into account */ aa_parseoptions( NULL, NULL, NULL, NULL ); diff --git a/modules/video_output/caca.c b/modules/video_output/caca.c index 67a6743a63..967dea8e68 100644 --- a/modules/video_output/caca.c +++ b/modules/video_output/caca.c @@ -163,10 +163,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } p_vout->p_sys->p_cv = cucul_create_canvas(0, 0); if( !p_vout->p_sys->p_cv ) diff --git a/modules/video_output/directfb.c b/modules/video_output/directfb.c index 512f2da6f6..3b82eaf901 100644 --- a/modules/video_output/directfb.c +++ b/modules/video_output/directfb.c @@ -89,10 +89,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) ); if( !p_sys ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } p_sys->p_directfb = NULL; p_sys->p_primary = NULL; diff --git a/modules/video_output/fb.c b/modules/video_output/fb.c index e34f3f373d..91b28ba0d1 100644 --- a/modules/video_output/fb.c +++ b/modules/video_output/fb.c @@ -186,10 +186,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate instance and initialize some members */ p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - }; memset( p_sys, 0, sizeof(vout_sys_t) ); p_vout->pf_init = Init; @@ -874,8 +871,6 @@ static int OpenDisplay( vout_thread_t *p_vout ) p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) ); if( !p_sys->p_palette ) { - msg_Err( p_vout, "out of memory" ); - /* Restore fb config */ ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info ); diff --git a/modules/video_output/ggi.c b/modules/video_output/ggi.c index f7b682c1e7..804e03a01a 100644 --- a/modules/video_output/ggi.c +++ b/modules/video_output/ggi.c @@ -104,10 +104,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return( 1 ); - } /* Open and initialize device */ if( OpenDisplay( p_vout ) ) diff --git a/modules/video_output/glide.c b/modules/video_output/glide.c index d70479e809..2c8c425f30 100644 --- a/modules/video_output/glide.c +++ b/modules/video_output/glide.c @@ -96,10 +96,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return( 1 ); - } /* Open and initialize device */ if( OpenDisplay( p_vout ) ) diff --git a/modules/video_output/hd1000v.cpp b/modules/video_output/hd1000v.cpp index 51f62cad4a..34a0213e66 100644 --- a/modules/video_output/hd1000v.cpp +++ b/modules/video_output/hd1000v.cpp @@ -97,10 +97,7 @@ static int Create( vlc_object_t *p_this ) p_vout->p_sys = (struct vout_sys_t*) malloc( sizeof(struct vout_sys_t) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); - return VLC_EGENERIC; - } + return VLC_ENOMEM; /* Allocate a screen for VLC vout. */ p_vout->p_sys->p_screen = new CascadeScreen(); diff --git a/modules/video_output/image.c b/modules/video_output/image.c index 215ab24ca5..4225b98700 100644 --- a/modules/video_output/image.c +++ b/modules/video_output/image.c @@ -315,6 +315,9 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic ) psz_prefix = psz_tmp; psz_filename = (char *)malloc( 10 + strlen( psz_prefix ) + strlen( p_vout->p_sys->psz_format ) ); + if( !psz_filename ) + return; + if( p_vout->p_sys->b_replace ) { sprintf( psz_filename, "%s.%s", psz_prefix, diff --git a/modules/video_output/mga.c b/modules/video_output/mga.c index fc8f88daf1..a9f53d9cdc 100644 --- a/modules/video_output/mga.c +++ b/modules/video_output/mga.c @@ -137,10 +137,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return( 1 ); - } p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR ); if( p_vout->p_sys->i_fd == -1 ) diff --git a/modules/video_output/msw/direct3d.c b/modules/video_output/msw/direct3d.c index 85b0754c6b..19c8efc133 100644 --- a/modules/video_output/msw/direct3d.c +++ b/modules/video_output/msw/direct3d.c @@ -153,10 +153,7 @@ static int OpenVideo( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) ); if( VLC_SUCCESS != Direct3DVoutCreate( p_vout ) ) diff --git a/modules/video_output/msw/directx.c b/modules/video_output/msw/directx.c index 552db7d803..ec72dcd134 100644 --- a/modules/video_output/msw/directx.c +++ b/modules/video_output/msw/directx.c @@ -210,10 +210,7 @@ static int OpenVideo( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) ); /* Initialisations */ diff --git a/modules/video_output/msw/events.c b/modules/video_output/msw/events.c index 2245bd6de1..f37d9520be 100644 --- a/modules/video_output/msw/events.c +++ b/modules/video_output/msw/events.c @@ -343,9 +343,12 @@ void EventThread( event_thread_t *p_event ) #ifdef UNICODE { wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 ); - mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2); - psz_title[strlen(val.psz_string)] = 0; - free( val.psz_string ); val.psz_string = (char *)psz_title; + if( psz_title ) + { + mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2); + psz_title[strlen(val.psz_string)] = 0; + free( val.psz_string ); val.psz_string = (char *)psz_title; + } } #endif diff --git a/modules/video_output/msw/glwin32.c b/modules/video_output/msw/glwin32.c index 3258e76d6f..b4db014b22 100644 --- a/modules/video_output/msw/glwin32.c +++ b/modules/video_output/msw/glwin32.c @@ -96,10 +96,7 @@ static int OpenVideo( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) ); /* Initialisations */ diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c index 504ae30cd9..13666f9b38 100644 --- a/modules/video_output/opengl.c +++ b/modules/video_output/opengl.c @@ -250,10 +250,7 @@ static int CreateVout( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) ); if( p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); - return VLC_EGENERIC; - } + return VLC_ENOMEM; var_Create( p_vout, "opengl-effect", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); @@ -409,17 +406,11 @@ static int Init( vout_thread_t *p_vout ) p_sys->pp_buffer[0] = malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch ); if( !p_sys->pp_buffer[0] ) - { - msg_Err( p_vout, "out of memory" ); return -1; - } p_sys->pp_buffer[1] = malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch ); if( !p_sys->pp_buffer[1] ) - { - msg_Err( p_vout, "out of memory" ); return -1; - } p_vout->p_picture[0].i_planes = 1; p_vout->p_picture[0].p->p_pixels = p_sys->pp_buffer[0]; diff --git a/modules/video_output/qte/qte.cpp b/modules/video_output/qte/qte.cpp index 9912f6026b..da41e4a479 100644 --- a/modules/video_output/qte/qte.cpp +++ b/modules/video_output/qte/qte.cpp @@ -143,10 +143,7 @@ static int Open( vlc_object_t *p_this ) p_vout->p_sys = (struct vout_sys_t*) malloc( sizeof( struct vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return( 1 ); - } p_vout->pf_init = Init; p_vout->pf_end = End; diff --git a/modules/video_output/x11/xcommon.c b/modules/video_output/x11/xcommon.c index 3560352414..be72fc9bb0 100644 --- a/modules/video_output/x11/xcommon.c +++ b/modules/video_output/x11/xcommon.c @@ -206,10 +206,7 @@ int Activate ( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } vlc_mutex_init( &p_vout->p_sys->lock ); @@ -2942,10 +2939,7 @@ static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout, p_data = malloc( i_bytes_per_line * i_height ); #endif if( !p_data ) - { - msg_Err( p_vout, "out of memory" ); return NULL; - } #ifdef MODULE_NAME_IS_x11 /* Optimize the quantum of a scanline regarding its size - the quantum is -- 2.39.2