From ad08a9c341505477e50eef9f8373cd0b607caaa5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Duraffort?= Date: Sat, 13 Dec 2008 16:24:24 +0100 Subject: [PATCH] Use calloc instead of malloc+memset. --- modules/access/dvb/en50221.c | 7 ++----- modules/access_filter/bandwidth.c | 6 +++--- modules/access_filter/dump.c | 5 ++--- modules/access_output/bonjour.c | 6 +----- modules/audio_output/pulse.c | 3 +-- modules/codec/avcodec/encoder.c | 3 +-- modules/codec/avcodec/video.c | 6 +----- modules/codec/cc.c | 5 +---- modules/codec/cdg.c | 5 +---- modules/codec/csri.c | 3 +-- modules/misc/rtsp.c | 18 ++++++++---------- modules/mux/mpeg/csa.c | 7 ++----- modules/mux/ogg.c | 6 ++---- modules/stream_out/transcode.c | 3 +-- 14 files changed, 27 insertions(+), 56 deletions(-) diff --git a/modules/access/dvb/en50221.c b/modules/access/dvb/en50221.c index f8c1dadc64..4b9ff7cee3 100644 --- a/modules/access/dvb/en50221.c +++ b/modules/access/dvb/en50221.c @@ -1368,9 +1368,7 @@ static void ConditionalAccessOpen( access_t * p_access, int i_session_id ) p_sys->p_sessions[i_session_id - 1].pf_handle = ConditionalAccessHandle; p_sys->p_sessions[i_session_id - 1].pf_close = ConditionalAccessClose; - p_sys->p_sessions[i_session_id - 1].p_sys = malloc(sizeof(system_ids_t)); - memset( p_sys->p_sessions[i_session_id - 1].p_sys, 0, - sizeof(system_ids_t) ); + p_sys->p_sessions[i_session_id - 1].p_sys = calloc( 1, sizeof(system_ids_t) ); APDUSend( p_access, i_session_id, AOT_CA_INFO_ENQ, NULL, 0 ); } @@ -1500,8 +1498,7 @@ static void DateTimeOpen( access_t * p_access, int i_session_id ) p_sys->p_sessions[i_session_id - 1].pf_handle = DateTimeHandle; p_sys->p_sessions[i_session_id - 1].pf_manage = DateTimeManage; p_sys->p_sessions[i_session_id - 1].pf_close = DateTimeClose; - p_sys->p_sessions[i_session_id - 1].p_sys = malloc(sizeof(date_time_t)); - memset( p_sys->p_sessions[i_session_id - 1].p_sys, 0, sizeof(date_time_t) ); + p_sys->p_sessions[i_session_id - 1].p_sys = calloc( 1, sizeof(date_time_t) ); DateTimeSend( p_access, i_session_id ); } diff --git a/modules/access_filter/bandwidth.c b/modules/access_filter/bandwidth.c index 995ee8aced..43bce412c4 100644 --- a/modules/access_filter/bandwidth.c +++ b/modules/access_filter/bandwidth.c @@ -87,11 +87,10 @@ static int Open (vlc_object_t *obj) access->pf_control = Control; access->info = src->info; - access_sys_t *p_sys = access->p_sys = malloc (sizeof (*p_sys)); - if (p_sys == NULL) + access_sys_t *p_sys = access->p_sys = calloc( 1, sizeof (*p_sys) ); + if( !p_sys ) return VLC_ENOMEM; - memset (p_sys, 0, sizeof (*p_sys)); p_sys->bandwidth = var_CreateGetInteger (access, "access-bandwidth"); p_sys->last_time = mdate (); @@ -175,3 +174,4 @@ static int Seek (access_t *access, int64_t offset) access->info = src->info; return ret; } + diff --git a/modules/access_filter/dump.c b/modules/access_filter/dump.c index 932e919033..37bb33d70b 100644 --- a/modules/access_filter/dump.c +++ b/modules/access_filter/dump.c @@ -109,10 +109,9 @@ static int Open (vlc_object_t *obj) access->pf_control = Control; access->info = src->info; - access_sys_t *p_sys = access->p_sys = malloc (sizeof (*p_sys)); - if (p_sys == NULL) + access_sys_t *p_sys = access->p_sys = calloc( 1, sizeof (*p_sys) ); + if( !p_sys ) return VLC_ENOMEM; - memset (p_sys, 0, sizeof (*p_sys)); # ifndef UNDER_CE if ((p_sys->stream = tmpfile ()) == NULL) diff --git a/modules/access_output/bonjour.c b/modules/access_output/bonjour.c index 6092c09000..89ce76178b 100644 --- a/modules/access_output/bonjour.c +++ b/modules/access_output/bonjour.c @@ -192,16 +192,12 @@ void *bonjour_start_service( vlc_object_t *p_log, const char *psz_stype, const char *psz_name, int i_port, char *psz_txt ) { int err; - bonjour_t *p_sys; - p_sys = (bonjour_t *)malloc( sizeof(*p_sys) ); + bonjour_t* p_sys = calloc( 1, sizeof(*p_sys) ); if( p_sys == NULL ) return NULL; - memset( p_sys, 0, sizeof(*p_sys) ); - p_sys->p_log = p_log; - p_sys->i_port = i_port; p_sys->psz_name = avahi_strdup( psz_name ); p_sys->psz_stype = avahi_strdup( psz_stype ); diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c index 848f72ae78..4ce9ccbf14 100644 --- a/modules/audio_output/pulse.c +++ b/modules/audio_output/pulse.c @@ -118,10 +118,9 @@ static int Open ( vlc_object_t *p_this ) struct pa_channel_map map; /* Allocate structures */ - p_aout->output.p_sys = p_sys = malloc( sizeof( aout_sys_t ) ); + p_aout->output.p_sys = p_sys = calloc( 1, sizeof( aout_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; - memset( p_sys, 0, sizeof( aout_sys_t ) ); PULSE_DEBUG( "Pulse start initialization"); diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c index 19519a1960..557b84bba2 100644 --- a/modules/codec/avcodec/encoder.c +++ b/modules/codec/avcodec/encoder.c @@ -263,9 +263,8 @@ int OpenEncoder( vlc_object_t *p_this ) } /* Allocate the memory needed to store the encoder's structure */ - if( ( p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL ) + if( ( p_sys = calloc( 1, sizeof(encoder_sys_t) ) ) == NULL ) return VLC_ENOMEM; - memset( p_sys, 0, sizeof(encoder_sys_t) ); p_enc->p_sys = p_sys; p_sys->p_codec = p_codec; diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c index 5c63fa262f..fffa7546fe 100644 --- a/modules/codec/avcodec/video.c +++ b/modules/codec/avcodec/video.c @@ -183,12 +183,8 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context, vlc_value_t val; /* Allocate the memory needed to store the decoder's structure */ - if( ( p_dec->p_sys = p_sys = - (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) - { + if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL ) return VLC_ENOMEM; - } - memset( p_sys, 0, sizeof(decoder_sys_t) ); p_dec->p_sys->p_context = p_context; p_dec->p_sys->p_codec = p_codec; diff --git a/modules/codec/cc.c b/modules/codec/cc.c index e00afb3742..af479914cb 100644 --- a/modules/codec/cc.c +++ b/modules/codec/cc.c @@ -199,14 +199,11 @@ static int Open( vlc_object_t *p_this ) p_dec->pf_decode_sub = Decode; /* Allocate the memory needed to store the decoder's structure */ - p_dec->p_sys = p_sys = malloc( sizeof( *p_sys ) ); + p_dec->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) ); if( p_sys == NULL ) return VLC_ENOMEM; /* init of p_sys */ - memset( p_sys, 0, sizeof( *p_sys ) ); - p_sys->i_block = 0; - p_sys->i_field = i_field; p_sys->i_channel = i_channel; diff --git a/modules/codec/cdg.c b/modules/codec/cdg.c index 3269061fbb..7dca2a581c 100644 --- a/modules/codec/cdg.c +++ b/modules/codec/cdg.c @@ -101,14 +101,11 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; /* Allocate the memory needed to store the decoder's structure */ - p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)); + p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ); if( !p_sys ) return VLC_ENOMEM; /* Init */ - memset( p_sys, 0, sizeof(*p_sys) ); - p_sys->i_offseth = 0; - p_sys->i_offsetv = 0; p_sys->p_screen = p_sys->screen; /* Set output properties diff --git a/modules/codec/csri.c b/modules/codec/csri.c index dfcd13b242..8d3f9e3a12 100644 --- a/modules/codec/csri.c +++ b/modules/codec/csri.c @@ -120,10 +120,9 @@ static int Create( vlc_object_t *p_this ) p_dec->pf_decode_sub = DecodeBlock; - p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) ); + p_dec->p_sys = p_sys = calloc( 1, sizeof( decoder_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; - memset( &p_sys->fmt_cached, 0, sizeof( p_sys->fmt_cached ) ); p_sys->p_stream_ext = p_stream_ext; p_sys->pf_push_packet = p_stream_ext->push_packet; diff --git a/modules/misc/rtsp.c b/modules/misc/rtsp.c index 5583c6499f..262cbc70c2 100644 --- a/modules/misc/rtsp.c +++ b/modules/misc/rtsp.c @@ -368,14 +368,13 @@ static void Close( vlc_object_t * p_this ) static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name, input_item_t *p_item ) { - vod_sys_t *p_sys = p_vod->p_sys; - vod_media_t *p_media = malloc( sizeof(vod_media_t) ); int i; + vod_sys_t *p_sys = p_vod->p_sys; + vod_media_t *p_media = calloc( 1, sizeof(vod_media_t) ); if( !p_media ) return NULL; - memset( p_media, 0, sizeof(vod_media_t) ); p_media->id = p_sys->i_media_id++; TAB_INIT( p_media->i_es, p_media->es ); p_media->psz_mux = NULL; @@ -498,11 +497,10 @@ static void MediaDel( vod_t *p_vod, vod_media_t *p_media ) static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt ) { - media_es_t *p_es = malloc( sizeof(media_es_t) ); char *psz_urlc; - - if( !p_es ) return VLC_ENOMEM; - memset( p_es, 0, sizeof(media_es_t) ); + media_es_t *p_es = calloc( 1, sizeof(media_es_t) ); + if( !p_es ) + return VLC_ENOMEM; free( p_media->psz_mux ); p_media->psz_mux = NULL; @@ -896,10 +894,10 @@ static void* CommandThread( vlc_object_t *p_this ) ****************************************************************************/ static rtsp_client_t *RtspClientNew( vod_media_t *p_media, char *psz_session ) { - rtsp_client_t *p_rtsp = malloc( sizeof(rtsp_client_t) ); + rtsp_client_t *p_rtsp = calloc( 1, sizeof(rtsp_client_t) ); - if( !p_rtsp ) return NULL; - memset( p_rtsp, 0, sizeof(rtsp_client_t) ); + if( !p_rtsp ) + return NULL; p_rtsp->es = 0; p_rtsp->psz_session = psz_session; diff --git a/modules/mux/mpeg/csa.c b/modules/mux/mpeg/csa.c index 9550297473..99ae905b57 100644 --- a/modules/mux/mpeg/csa.c +++ b/modules/mux/mpeg/csa.c @@ -66,16 +66,13 @@ static void csa_BlockCypher( uint8_t kk[57], uint8_t bd[8], uint8_t ib[8] ); *****************************************************************************/ csa_t *csa_New( void ) { - csa_t *c = malloc( sizeof( csa_t ) ); - memset( c, 0, sizeof( csa_t ) ); - - return c; + return calloc( 1, sizeof( csa_t ) ); } /***************************************************************************** * csa_Delete: *****************************************************************************/ -void csa_Delete( csa_t *c ) +void csa_Delete( csa_t *c ) { free( c ); } diff --git a/modules/mux/ogg.c b/modules/mux/ogg.c index 26ddeee4ca..b767ed634e 100644 --- a/modules/mux/ogg.c +++ b/modules/mux/ogg.c @@ -354,13 +354,12 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) case VLC_FOURCC( 'W', 'M', 'V', '2' ): case VLC_FOURCC( 'W', 'M', 'V', '3' ): case VLC_FOURCC( 'S', 'N', 'O', 'W' ): - p_stream->p_oggds_header = malloc( sizeof(oggds_header_t) ); + p_stream->p_oggds_header = calloc( 1, sizeof(oggds_header_t) ); if( !p_stream->p_oggds_header ) { free( p_stream ); return VLC_ENOMEM; } - memset( p_stream->p_oggds_header, 0, sizeof(oggds_header_t) ); p_stream->p_oggds_header->i_packet_type = PACKET_TYPE_HEADER; memcpy( p_stream->p_oggds_header->stream_type, "video", 5 ); @@ -476,13 +475,12 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) switch( p_stream->i_fourcc ) { case VLC_FOURCC( 's', 'u','b', 't' ): - p_stream->p_oggds_header = malloc( sizeof(oggds_header_t) ); + p_stream->p_oggds_header = calloc( 1, sizeof(oggds_header_t) ); if( !p_stream->p_oggds_header ) { free( p_stream ); return VLC_ENOMEM; } - memset( p_stream->p_oggds_header, 0, sizeof(oggds_header_t) ); p_stream->p_oggds_header->i_packet_type = PACKET_TYPE_HEADER; memcpy( p_stream->p_oggds_header->stream_type, "text", 4 ); diff --git a/modules/stream_out/transcode.c b/modules/stream_out/transcode.c index 4a7680e902..2b8cbdbf9f 100644 --- a/modules/stream_out/transcode.c +++ b/modules/stream_out/transcode.c @@ -693,10 +693,9 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) sout_stream_sys_t *p_sys = p_stream->p_sys; sout_stream_id_t *id; - id = malloc( sizeof( sout_stream_id_t ) ); + id = calloc( 1, sizeof( sout_stream_id_t ) ); if( !id ) goto error; - memset( id, 0, sizeof(sout_stream_id_t) ); id->id = NULL; id->p_decoder = NULL; -- 2.39.2