From 15643af12d9eb61eff8a8e89d8170f3d2b73d7e1 Mon Sep 17 00:00:00 2001 From: JP Dinger Date: Sat, 5 Dec 2009 15:24:19 +0100 Subject: [PATCH] Replace argument = realloc( argument, size ); with realloc_or_free() in modules/*, and while at it add assert( argument ) to mark unhandled ENOMEM conditions, also for malloc(). --- modules/access/dshow/dshow.cpp | 14 ++++++--- modules/access/dvb/en50221.c | 14 +++++++++ modules/access/jack.c | 1 + modules/access/mms/buffer.c | 27 +++++++--------- modules/access/mms/mmsh.c | 6 +++- modules/access/mms/mmstu.c | 9 ++++-- modules/access/rtsp/real.c | 20 ++++-------- modules/access_output/http.c | 15 ++++++--- modules/audio_filter/converter/dtstospdif.c | 9 ++++-- modules/audio_output/alsa.c | 12 ++++--- modules/audio_output/waveout.c | 11 ++++--- modules/codec/cmml/history.c | 2 +- modules/codec/cmml/xarray.c | 4 ++- modules/codec/cmml/xurl.c | 7 ++++- modules/codec/dvbsub.c | 16 ++++++---- modules/codec/flac.c | 12 +++++-- modules/codec/kate.c | 13 +++++--- modules/codec/quicktime.c | 6 +++- modules/codec/realvideo.c | 6 ++-- modules/codec/speex.c | 17 +++++++--- modules/codec/subtitles/subsdec.c | 9 +++++- modules/codec/subtitles/subsusf.c | 4 ++- modules/codec/theora.c | 20 +++++++----- modules/codec/vorbis.c | 15 ++++++--- modules/control/http/macro.c | 23 ++++++++++---- modules/control/http/mvar.c | 11 +++++-- modules/control/http/util.c | 10 +++++- modules/control/rc.c | 7 ++++- modules/control/telnet.c | 13 ++++++-- modules/demux/asademux.c | 10 +++++- modules/demux/avi/avi.c | 5 +-- modules/demux/gme.cpp | 10 ++++-- modules/demux/live555.cpp | 14 +++++++-- modules/demux/mkv/chapters.cpp | 7 ++++- modules/demux/mkv/matroska_segment.cpp | 31 +++++++++++++++---- modules/demux/nuv.c | 6 ++-- modules/demux/ogg.c | 8 ++--- modules/demux/playlist/asx.c | 12 ++++++- modules/demux/ps.h | 5 +-- modules/demux/subtitle.c | 30 +++++++++++------- modules/demux/subtitle_asa.c | 5 +-- modules/demux/ts.c | 15 +++++++-- modules/demux/vobsub.c | 15 +++++++-- modules/gui/qnx/vout.c | 11 ++----- modules/misc/freetype.c | 19 ++++++++---- modules/misc/text_renderer.h | 8 ++--- modules/misc/xml/xtag.c | 18 ++++++----- modules/mux/avi.c | 8 +++-- modules/mux/mp4.c | 12 ++++--- modules/mux/ogg.c | 9 ++++-- modules/packetizer/mpeg4video.c | 7 ++++- modules/packetizer/vc1.c | 7 ++++- modules/services_discovery/sap.c | 1 + modules/stream_out/bridge.c | 13 ++++++-- modules/stream_out/mosaic_bridge.c | 10 ++++-- modules/stream_out/raop.c | 3 +- modules/video_filter/audiobargraph_v.c | 6 +++- modules/video_filter/bluescreen.c | 7 ++++- .../dynamicoverlay/dynamicoverlay_list.c | 5 +-- modules/video_filter/gaussianblur.c | 13 +++++--- modules/video_filter/mosaic.c | 23 +++++++++----- modules/video_filter/rss.c | 9 ++++-- modules/video_output/msw/directx.c | 9 +++--- 63 files changed, 494 insertions(+), 210 deletions(-) diff --git a/modules/access/dshow/dshow.cpp b/modules/access/dshow/dshow.cpp index b965bcd3d8..bcdcda831e 100644 --- a/modules/access/dshow/dshow.cpp +++ b/modules/access/dshow/dshow.cpp @@ -34,6 +34,8 @@ #define __STDC_FORMAT_MACROS 1 #include +#include + #include #include #include @@ -41,6 +43,7 @@ #include #include #include +#include #include "common.h" #include "filter.h" @@ -1101,8 +1104,9 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys, dshow_stream.p_device_filter = p_device_filter; dshow_stream.p_capture_filter = p_capture_filter; - p_sys->pp_streams = (dshow_stream_t **)realloc( p_sys->pp_streams, + p_sys->pp_streams = realloc_or_free( p_sys->pp_streams, sizeof(dshow_stream_t *) * (p_sys->i_streams + 1) ); + assert( p_sys->pp_streams ); p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t; *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream; @@ -1963,12 +1967,12 @@ static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name, if( !list_devices.size() ) return VLC_SUCCESS; - p_item->ppsz_list = - (char **)realloc( p_item->ppsz_list, + p_item->ppsz_list = realloc_or_free( p_item->ppsz_list, (list_devices.size()+3) * sizeof(char *) ); - p_item->ppsz_list_text = - (char **)realloc( p_item->ppsz_list_text, + assert( p_item->ppsz_list ); + p_item->ppsz_list_text = realloc_or_free( p_item->ppsz_list_text, (list_devices.size()+3) * sizeof(char *) ); + assert( p_item->ppsz_list_text ); list::iterator iter; for( iter = list_devices.begin(), i = 2; iter != list_devices.end(); diff --git a/modules/access/dvb/en50221.c b/modules/access/dvb/en50221.c index 2f16fd4700..d17a24aa84 100644 --- a/modules/access/dvb/en50221.c +++ b/modules/access/dvb/en50221.c @@ -273,6 +273,7 @@ static int TPDURecv( access_t * p_access, uint8_t i_slot, uint8_t *pi_tag, if ( pi_size == NULL ) { p_data = malloc( MAX_TPDU_SIZE ); + assert( p_data ); } for ( ; ; ) @@ -358,6 +359,8 @@ static int SPDUSend( access_t * p_access, int i_session_id, uint8_t i_tag; uint8_t i_slot = p_sys->p_sessions[i_session_id - 1].i_slot; + assert( p_spdu ); + *p++ = ST_SESSION_NUMBER; *p++ = 0x02; *p++ = (i_session_id >> 8); @@ -806,6 +809,8 @@ static int APDUSend( access_t * p_access, int i_session_id, int i_tag, ca_msg_t ca_msg; int i_ret; + assert( p_apdu ); + *p++ = (i_tag >> 16); *p++ = (i_tag >> 8) & 0xff; *p++ = i_tag & 0xff; @@ -1051,6 +1056,8 @@ static uint8_t *CAPMTHeader( system_ids_t *p_ids, uint8_t i_list_mgt, else p_data = malloc( 6 ); + assert( p_data ); + p_data[0] = i_list_mgt; p_data[1] = i_program_number >> 8; p_data[2] = i_program_number & 0xff; @@ -1105,6 +1112,8 @@ static uint8_t *CAPMTES( system_ids_t *p_ids, uint8_t *p_capmt, else p_data = realloc( p_capmt, i_capmt_size + 5 ); + assert( p_data ); + i = i_capmt_size; p_data[i] = i_type; @@ -1573,6 +1582,7 @@ static void MMISendObject( access_t *p_access, int i_session_id, i_tag = AOT_ANSW; i_size = 1 + strlen( p_object->u.answ.psz_answ ); p_data = malloc( i_size ); + assert( p_data ); p_data[0] = (p_object->u.answ.b_ok == true) ? 0x1 : 0x0; strncpy( (char *)&p_data[1], p_object->u.answ.psz_answ, i_size - 1 ); break; @@ -1581,6 +1591,7 @@ static void MMISendObject( access_t *p_access, int i_session_id, i_tag = AOT_MENU_ANSW; i_size = 1; p_data = malloc( i_size ); + assert( p_data ); p_data[0] = p_object->u.menu_answ.i_choice; break; @@ -1667,6 +1678,7 @@ static void MMIHandleEnq( access_t *p_access, int i_session_id, d += 2; /* skip answer_text_length because it is not mandatory */ l -= 2; p_mmi->last_object.u.enq.psz_text = malloc( l + 1 ); + assert( p_mmi->last_object.u.enq.psz_text ); strncpy( p_mmi->last_object.u.enq.psz_text, (char *)d, l ); p_mmi->last_object.u.enq.psz_text[l] = '\0'; @@ -1810,6 +1822,7 @@ static void MMIOpen( access_t *p_access, int i_session_id ) p_sys->p_sessions[i_session_id - 1].pf_close = MMIClose; p_sys->p_sessions[i_session_id - 1].p_sys = malloc(sizeof(mmi_t)); p_mmi = (mmi_t *)p_sys->p_sessions[i_session_id - 1].p_sys; + assert( p_mmi ); p_mmi->last_object.i_object_type = EN50221_MMI_NONE; } @@ -2440,6 +2453,7 @@ char *dvbsi_to_utf8( const char *psz_instring, size_t i_length ) i_in = i_length - (psz_stringstart - psz_instring ); i_out = i_in * 6; psz_outstring = psz_tmp = (char*)malloc( i_out + 1 ); + assert( psz_outstring ); vlc_iconv( iconv_handle, &psz_stringstart, &i_in, &psz_tmp, &i_out ); vlc_iconv_close( iconv_handle ); *psz_tmp = '\0'; diff --git a/modules/access/jack.c b/modules/access/jack.c index 0ff2a81834..fbbac2d08d 100644 --- a/modules/access/jack.c +++ b/modules/access/jack.c @@ -543,6 +543,7 @@ static void Port_finder( demux_t *p_demux ) /* alloc an array to store all the matched ports */ p_sys->pp_jack_port_table = realloc( p_sys->pp_jack_port_table, (i_out_ports * sizeof( char * ) + i_total_out_ports * sizeof( char * ) ) ); + assert( p_sys->pp_jack_port_table ); for(int i=0; i + #include +#include #include "asf.h" #include "buffer.h" @@ -41,11 +44,8 @@ int var_buffer_initwrite( var_buffer_t *p_buf, int i_default_size ) { p_buf->i_size = ( i_default_size > 0 ) ? i_default_size : 2048; p_buf->i_data = 0; - if( !( p_buf->p_data = malloc( p_buf->i_size ) ) ) - { - return( -1 ); - } - return( 0 ); + p_buf->p_data = malloc( p_buf->i_size ); + return p_buf->p_data ? 0 : -1; } int var_buffer_reinitwrite( var_buffer_t *p_buf, int i_default_size ) @@ -62,11 +62,7 @@ int var_buffer_reinitwrite( var_buffer_t *p_buf, int i_default_size ) p_buf->i_size = ( i_default_size > 0 ) ? i_default_size : 2048; p_buf->p_data = malloc( p_buf->i_size ); } - if( !p_buf->p_data ) - { - return( -1 ); - } - return( 0 ); + return p_buf->p_data ? 0 : -1; } void var_buffer_add8 ( var_buffer_t *p_buf, uint8_t i_byte ) @@ -75,7 +71,8 @@ void var_buffer_add8 ( var_buffer_t *p_buf, uint8_t i_byte ) if( p_buf->i_data >= p_buf->i_size ) { p_buf->i_size += 1024; - p_buf->p_data = realloc( p_buf->p_data, p_buf->i_size ); + p_buf->p_data = realloc_or_free( p_buf->p_data, p_buf->i_size ); + assert( p_buf->p_data ); } p_buf->p_data[p_buf->i_data] = i_byte&0xff; p_buf->i_data++; @@ -105,12 +102,11 @@ void var_buffer_addmemory( var_buffer_t *p_buf, void *p_mem, int i_mem ) if( p_buf->i_data + i_mem >= p_buf->i_size ) { p_buf->i_size += i_mem + 1024; - p_buf->p_data = realloc( p_buf->p_data, p_buf->i_size ); + p_buf->p_data = realloc_or_free( p_buf->p_data, p_buf->i_size ); + assert( p_buf->p_data ); } - memcpy( p_buf->p_data + p_buf->i_data, - p_mem, - i_mem ); + memcpy( p_buf->p_data + p_buf->i_data, p_mem, i_mem ); p_buf->i_data += i_mem; } @@ -129,6 +125,7 @@ void var_buffer_addUTF16( var_buffer_t *p_buf, const char *p_str ) char *psz_out, *psz_tmp; psz_out = psz_tmp = malloc( i_out + 1 ); + assert( psz_out ); iconv_handle = vlc_iconv_open( "UTF-16LE", "UTF-8" ); vlc_iconv( iconv_handle, &p_str, &i_in, &psz_tmp, &i_out ); vlc_iconv_close( iconv_handle ); diff --git a/modules/access/mms/mmsh.c b/modules/access/mms/mmsh.c index 688ad524bc..98784b21b9 100644 --- a/modules/access/mms/mmsh.c +++ b/modules/access/mms/mmsh.c @@ -29,10 +29,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #include #include @@ -734,7 +737,8 @@ static void GetHeader( access_t *p_access ) if( ck.i_data > 0 ) { p_sys->i_header += ck.i_data; - p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header ); + p_sys->p_header = realloc_or_free( p_sys->p_header, p_sys->i_header ); + assert( p_sys->p_header ); memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data], ck.p_data, ck.i_data ); } diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c index c3277220e3..89a772aefc 100644 --- a/modules/access/mms/mmstu.c +++ b/modules/access/mms/mmstu.c @@ -604,6 +604,7 @@ static int MMSOpen( access_t *p_access, vlc_url_t *p_url, int i_proto ) { \ int i; \ psz = malloc( size + 1); \ + assert( psz ); \ for( i = 0; i < size; i++ ) \ { \ psz[i] = p[i]; \ @@ -1186,6 +1187,7 @@ static int mms_ParseCommand( access_t *p_access, free( p_sys->p_cmd ); p_sys->i_cmd = i_data; p_sys->p_cmd = malloc( i_data ); + assert( p_sys->p_cmd ); memcpy( p_sys->p_cmd, p_data, i_data ); *pi_used = i_data; /* by default */ @@ -1308,8 +1310,9 @@ static int mms_ParsePacket( access_t *p_access, { if( p_sys->p_header ) { - p_sys->p_header = realloc( p_sys->p_header, - p_sys->i_header + i_packet_length - 8 ); + p_sys->p_header = realloc_or_free( p_sys->p_header, + p_sys->i_header + i_packet_length - 8 ); + assert( p_sys->p_header ); memcpy( &p_sys->p_header[p_sys->i_header], p_data + 8, i_packet_length - 8 ); p_sys->i_header += i_packet_length - 8; @@ -1318,6 +1321,7 @@ static int mms_ParsePacket( access_t *p_access, else { uint8_t* p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader + assert( p_packet ); memcpy( p_packet, p_data + 8, i_packet_length - 8 ); p_sys->p_header = p_packet; p_sys->i_header = i_packet_length - 8; @@ -1331,6 +1335,7 @@ static int mms_ParsePacket( access_t *p_access, else { uint8_t* p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader + assert( p_packet ); memcpy( p_packet, p_data + 8, i_packet_length - 8 ); FREENULL( p_sys->p_media ); p_sys->p_media = p_packet; diff --git a/modules/access/rtsp/real.c b/modules/access/rtsp/real.c index d70e111dae..9bd4c87d65 100644 --- a/modules/access/rtsp/real.c +++ b/modules/access/rtsp/real.c @@ -28,6 +28,7 @@ #endif #include +#include #include "rtsp.h" #include "real.h" @@ -49,15 +50,6 @@ static const unsigned char xor_table[] = { #define LE_32C(x,y) do {uint32_t in=y; *(uint32_t *)(x)=GetDWLE(&in);} while(0) #define MAX(x,y) ((x>y) ? x : y) -/* XXX find a better place for this */ -static inline void *realloc_(void *p, size_t sz) -{ - void *n = realloc(p, sz); - if( !n ) - free(p); - return n; -} - static void hash(char *field, char *param) { uint32_t a, b, c, d; @@ -698,27 +690,27 @@ rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandw /* setup our streams */ real_calc_response_and_checksum (challenge2, checksum, challenge1); - buf = realloc_(buf, strlen(challenge2) + strlen(checksum) + 32); + buf = realloc_or_free(buf, strlen(challenge2) + strlen(checksum) + 32); if( !buf ) goto error; sprintf(buf, "RealChallenge2: %s, sd=%s", challenge2, checksum); rtsp_schedule_field(rtsp_session, buf); - buf = realloc_(buf, strlen(session_id) + 32); + buf = realloc_or_free(buf, strlen(session_id) + 32); if( !buf ) goto error; sprintf(buf, "If-Match: %s", session_id); rtsp_schedule_field(rtsp_session, buf); rtsp_schedule_field(rtsp_session, "Transport: x-pn-tng/tcp;mode=play,rtp/avp/tcp;unicast;mode=play"); - buf = realloc_(buf, strlen(mrl) + 32); + buf = realloc_or_free(buf, strlen(mrl) + 32); if( !buf ) goto error; sprintf(buf, "%s/streamid=0", mrl); rtsp_request_setup(rtsp_session,buf); if (h->prop->num_streams > 1) { rtsp_schedule_field(rtsp_session, "Transport: x-pn-tng/tcp;mode=play,rtp/avp/tcp;unicast;mode=play"); - buf = realloc_(buf, strlen(session_id) + 32); + buf = realloc_or_free(buf, strlen(session_id) + 32); if( !buf ) goto error; sprintf(buf, "If-Match: %s", session_id); rtsp_schedule_field(rtsp_session, buf); - buf = realloc_(buf, strlen(mrl) + 32); + buf = realloc_or_free(buf, strlen(mrl) + 32); if( !buf ) goto error; sprintf(buf, "%s/streamid=1", mrl); rtsp_request_setup(rtsp_session,buf); diff --git a/modules/access_output/http.c b/modules/access_output/http.c index f0e120dc62..b45ffe0674 100644 --- a/modules/access_output/http.c +++ b/modules/access_output/http.c @@ -30,14 +30,15 @@ # include "config.h" #endif +#include + #include #include #include #include - - #include #include +#include #if 0 //def HAVE_AVAHI_CLIENT #include "bonjour.h" @@ -319,11 +320,16 @@ static int Open( vlc_object_t *p_this ) p_sys->i_header_size = 0; p_sys->p_header = malloc( p_sys->i_header_allocated ); p_sys->b_header_complete = false; + if( !p_sys->p_header ) + p_sys->i_header_allocated = 0; p_access->pf_write = Write; p_access->pf_seek = Seek; p_access->pf_control = Control; + /* XXX Do we deal gracefully with p_sys->p_header == NULL? */ + assert( p_sys->p_header ); + return VLC_SUCCESS; } @@ -393,8 +399,9 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) { p_sys->i_header_allocated = p_buffer->i_buffer + p_sys->i_header_size + 1024; - p_sys->p_header = - realloc( p_sys->p_header, p_sys->i_header_allocated ); + p_sys->p_header = realloc_or_free( p_sys->p_header, + p_sys->i_header_allocated ); + assert( p_sys->p_header ); } memcpy( &p_sys->p_header[p_sys->i_header_size], p_buffer->p_buffer, diff --git a/modules/audio_filter/converter/dtstospdif.c b/modules/audio_filter/converter/dtstospdif.c index 7d62c6d178..49a61e82e1 100644 --- a/modules/audio_filter/converter/dtstospdif.c +++ b/modules/audio_filter/converter/dtstospdif.c @@ -28,12 +28,16 @@ # include "config.h" #endif +#include + #include #include #include #include +#include + /***************************************************************************** * Local structures *****************************************************************************/ @@ -125,8 +129,9 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf ) p_filter->p_sys->i_frame_size, p_in_buf->i_buffer ); p_filter->p_sys->i_frame_size = p_in_buf->i_buffer; - p_filter->p_sys->p_buf = realloc( p_filter->p_sys->p_buf, - p_in_buf->i_buffer * 3 ); + p_filter->p_sys->p_buf = realloc_or_free( p_filter->p_sys->p_buf, + p_in_buf->i_buffer * 3 ); + assert( p_filter->p_sys->p_buf ); p_filter->p_sys->i_frames = 0; } diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c index e4eaf8b30e..84e3fd5e7f 100644 --- a/modules/audio_output/alsa.c +++ b/modules/audio_output/alsa.c @@ -31,6 +31,8 @@ # include "config.h" #endif +#include + #include #include @@ -40,6 +42,8 @@ #include #include +#include + /* ALSA part Note: we use the new API which is available since 0.9.0beta10a. */ #define ALSA_PCM_NEW_HW_PARAMS_API @@ -1000,12 +1004,12 @@ static void GetDevicesForCard( module_config_t *p_item, int i_card ) break; } - p_item->ppsz_list = - (char **)realloc( p_item->ppsz_list, + p_item->ppsz_list = realloc_or_free( p_item->ppsz_list, (p_item->i_list + 2) * sizeof(char *) ); - p_item->ppsz_list_text = - (char **)realloc( p_item->ppsz_list_text, + assert( p_item->ppsz_list ); + p_item->ppsz_list_text = realloc_or_free( p_item->ppsz_list_text, (p_item->i_list + 2) * sizeof(char *) ); + assert( p_item->ppsz_list_text ); p_item->ppsz_list[ p_item->i_list ] = psz_device; p_item->ppsz_list_text[ p_item->i_list ] = psz_descr; p_item->i_list++; diff --git a/modules/audio_output/waveout.c b/modules/audio_output/waveout.c index 8f584afaba..71497d6368 100644 --- a/modules/audio_output/waveout.c +++ b/modules/audio_output/waveout.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #include #include @@ -1171,12 +1174,12 @@ static int ReloadWaveoutDevices( vlc_object_t *p_this, char const *psz_name, int wave_devices = waveOutGetNumDevs(); - p_item->ppsz_list = - (char **)realloc( p_item->ppsz_list, + p_item->ppsz_list = realloc_or_free( p_item->ppsz_list, (wave_devices+2) * sizeof(char *) ); - p_item->ppsz_list_text = - (char **)realloc( p_item->ppsz_list_text, + assert( p_item->ppsz_list ); + p_item->ppsz_list_text = realloc_or_free( p_item->ppsz_list_text, (wave_devices+2) * sizeof(char *) ); + assert( p_item->ppsz_list_text ); WAVEOUTCAPS caps; char sz_dev_name[MAXPNAMELEN+32]; diff --git a/modules/codec/cmml/history.c b/modules/codec/cmml/history.c index 702ae300d3..da82cbc5f5 100644 --- a/modules/codec/cmml/history.c +++ b/modules/codec/cmml/history.c @@ -36,7 +36,7 @@ #include "xarray.h" #ifdef HAVE_STDLIB_H -# include /* realloc() */ +# include /* malloc() */ #endif #undef HISTORY_DEBUG diff --git a/modules/codec/cmml/xarray.c b/modules/codec/cmml/xarray.c index 73eeb635fc..f33d47c14f 100644 --- a/modules/codec/cmml/xarray.c +++ b/modules/codec/cmml/xarray.c @@ -32,6 +32,8 @@ #include #include "xarray.h" +#include + /* local prototypes */ XArray * xarray_New (unsigned int); @@ -50,7 +52,7 @@ XArray * xarray_New (unsigned int); #define XARRAY_GROW_ARRAY(xarray) \ { \ - xarray->array = (void *) realloc (xarray->array, xarray->size * 2); \ + xarray->array = realloc_or_free (xarray->array, xarray->size * 2); \ if (xarray->array == NULL) return XARRAY_ENOMEM; \ } diff --git a/modules/codec/cmml/xurl.c b/modules/codec/cmml/xurl.c index ec4ad75da6..1f40e0e3c6 100644 --- a/modules/codec/cmml/xurl.c +++ b/modules/codec/cmml/xurl.c @@ -28,6 +28,9 @@ #endif #include +#include + +#include #include "xurl.h" @@ -383,6 +386,7 @@ char *XURL_GetHead( const char *psz_path ) i_characters_until_last_slash = pc_last_slash - psz_path; psz_path_head = malloc( i_characters_until_last_slash + 1 ); + assert( psz_path_head ); strncpy( psz_path_head, psz_path, i_characters_until_last_slash + 1 ); /* terminate the resulting string with '\0' */ @@ -435,7 +439,8 @@ static char *streallocat( char *psz_string, const char *psz_to_append ) size_t i_new_string_length = strlen( psz_string ) + strlen( psz_to_append ) + 1; - psz_string = (char *) realloc( psz_string, i_new_string_length ); + psz_string = realloc_or_free( psz_string, i_new_string_length ); + assert( psz_string ); return strcat( psz_string, psz_to_append ); } diff --git a/modules/codec/dvbsub.c b/modules/codec/dvbsub.c index bb7d835373..47ad7db126 100644 --- a/modules/codec/dvbsub.c +++ b/modules/codec/dvbsub.c @@ -75,6 +75,7 @@ #include #include #include +#include #include @@ -914,6 +915,7 @@ static void decode_region_composition( decoder_t *p_dec, bs_t *s ) } p_region->p_pixbuf = malloc( i_height * i_width ); + assert( p_region->p_pixbuf ); p_region->i_depth = 0; b_fill = true; } @@ -947,9 +949,9 @@ static void decode_region_composition( decoder_t *p_dec, bs_t *s ) /* We create a new object */ p_region->i_object_defs++; - p_region->p_object_defs = - realloc( p_region->p_object_defs, + p_region->p_object_defs = realloc_or_free( p_region->p_object_defs, sizeof(dvbsub_objectdef_t) * p_region->i_object_defs ); + assert( p_region->p_object_defs ); /* We parse object properties */ p_obj = &p_region->p_object_defs[p_region->i_object_defs - 1]; @@ -1165,8 +1167,9 @@ static void decode_object( decoder_t *p_dec, bs_t *s ) if( p_region->p_object_defs[i].i_id != i_id ) continue; p_region->p_object_defs[i].psz_text = - realloc( p_region->p_object_defs[i].psz_text, + realloc_or_free( p_region->p_object_defs[i].psz_text, i_number_of_codes + 1 ); + assert( p_region->p_object_defs[i].psz_text ); /* FIXME 16bits -> char ??? See Preamble */ for( j = 0; j < i_number_of_codes; j++ ) @@ -1840,6 +1843,7 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic ) #ifndef RANDOM_DITHERING pi_delta = malloc( ( p_region->p_picture->p[0].i_pitch + 1 ) * sizeof(int) * 4 ); + assert( pi_delta ); for( i = 0; i < (p_region->p_picture->p[0].i_pitch + 1) * 4 ; i++ ) { pi_delta[ i ] = 0; @@ -2078,9 +2082,9 @@ static void encode_page_composition( encoder_t *p_enc, bs_t *s, { encoder_region_t region; region.i_width = region.i_height = 0; - p_sys->p_regions = - realloc( p_sys->p_regions, sizeof(encoder_region_t) * - (p_sys->i_regions + 1) ); + p_sys->p_regions = realloc_or_free( p_sys->p_regions, + sizeof(encoder_region_t) * (p_sys->i_regions + 1) ); + assert( p_sys->p_regions ); p_sys->p_regions[p_sys->i_regions++] = region; } diff --git a/modules/codec/flac.c b/modules/codec/flac.c index 6b21e1a4e0..13f0e3020b 100644 --- a/modules/codec/flac.c +++ b/modules/codec/flac.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #ifdef HAVE_FLAC_STREAM_DECODER_H # include @@ -362,8 +365,9 @@ static void ProcessHeader( decoder_t *p_dec ) if( p_dec->fmt_out.i_codec == VLC_CODEC_FLAC ) { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; - p_dec->fmt_out.p_extra = - realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); + p_dec->fmt_out.p_extra = realloc_or_free( p_dec->fmt_out.p_extra, + p_dec->fmt_out.i_extra ); + assert( p_dec->fmt_out.p_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } @@ -1368,7 +1372,8 @@ static block_t *Encode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) if( p_sys->i_buffer < p_aout_buf->i_buffer * 2 ) { p_sys->p_buffer = - realloc( p_sys->p_buffer, p_aout_buf->i_buffer * 2 ); + realloc_or_free( p_sys->p_buffer, p_aout_buf->i_buffer * 2 ); + assert( p_sys->p_buffer ); p_sys->i_buffer = p_aout_buf->i_buffer * 2; } @@ -1437,6 +1442,7 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder, /* Backup the STREAMINFO metadata block */ p_enc->fmt_out.i_extra = STREAMINFO_SIZE + 4; p_enc->fmt_out.p_extra = malloc( STREAMINFO_SIZE + 4 ); + assert( p_enc->fmt_out.p_extra ); memcpy( p_enc->fmt_out.p_extra, "fLaC", 4 ); memcpy( ((uint8_t *)p_enc->fmt_out.p_extra) + 4, buffer, STREAMINFO_SIZE ); diff --git a/modules/codec/kate.c b/modules/codec/kate.c index 6051554d52..d2bf064e9f 100644 --- a/modules/codec/kate.c +++ b/modules/codec/kate.c @@ -28,11 +28,14 @@ # include "config.h" #endif +#include + #include #include #include #include #include +#include #include #ifdef HAVE_TIGER @@ -503,8 +506,9 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) /* Backup headers as extra data */ uint8_t *p_extra; - p_dec->fmt_in.p_extra = - realloc( p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra + kp.nbytes + 2 ); + p_dec->fmt_in.p_extra = realloc_or_free( p_dec->fmt_in.p_extra, + p_dec->fmt_in.i_extra + kp.nbytes + 2 ); + assert( p_dec->fmt_in.p_extra ); p_extra = (void*)(((unsigned char*)p_dec->fmt_in.p_extra) + p_dec->fmt_in.i_extra); *(p_extra++) = kp.nbytes >> 8; *(p_extra++) = kp.nbytes & 0xFF; @@ -624,8 +628,9 @@ static int ProcessHeaders( decoder_t *p_dec ) else { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; - p_dec->fmt_out.p_extra = - realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); + p_dec->fmt_out.p_extra = realloc_or_free( p_dec->fmt_out.p_extra, + p_dec->fmt_out.i_extra ); + assert( p_dec->fmt_out.p_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } diff --git a/modules/codec/quicktime.c b/modules/codec/quicktime.c index d902a6e955..106e5a6260 100644 --- a/modules/codec/quicktime.c +++ b/modules/codec/quicktime.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #if !defined (__APPLE__) && !defined(WIN32) # define LOADER 1 @@ -582,7 +585,8 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block ) if( p_sys->i_buffer_size < p_sys->i_buffer + p_block->i_buffer ) { p_sys->i_buffer_size = p_sys->i_buffer + p_block->i_buffer + 1024; - p_sys->p_buffer = realloc( p_sys->p_buffer, p_sys->i_buffer_size ); + p_sys->p_buffer = realloc_or_free( p_sys->p_buffer, p_sys->i_buffer_size ); + assert( p_sys->p_buffer ); } memcpy( &p_sys->p_buffer[p_sys->i_buffer], p_block->p_buffer, p_block->i_buffer ); diff --git a/modules/codec/realvideo.c b/modules/codec/realvideo.c index 25da2fc42c..8c00e9bd98 100644 --- a/modules/codec/realvideo.c +++ b/modules/codec/realvideo.c @@ -26,6 +26,8 @@ # include "config.h" #endif +#include + #include #include #include @@ -213,8 +215,8 @@ static int InitVideo(decoder_t *p_dec) int i_vide = p_dec->fmt_in.i_extra; unsigned int *p_vide = p_dec->fmt_in.p_extra; - decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) ); - memset(p_sys,0,sizeof( decoder_sys_t ) ); + decoder_sys_t *p_sys = calloc( 1, sizeof( decoder_sys_t ) ); + assert( p_sys ); if( i_vide < 8 ) { diff --git a/modules/codec/speex.c b/modules/codec/speex.c index b5e0cdf33c..d7ec977c19 100644 --- a/modules/codec/speex.c +++ b/modules/codec/speex.c @@ -28,11 +28,14 @@ # include "config.h" #endif +#include + #include #include #include #include #include +#include #include #include @@ -306,9 +309,9 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { uint8_t *p_extra; - p_dec->fmt_in.p_extra = - realloc( p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra + - oggpacket.bytes + 2 ); + p_dec->fmt_in.p_extra = realloc_or_free( p_dec->fmt_in.p_extra, + p_dec->fmt_in.i_extra + oggpacket.bytes + 2 ); + assert( p_dec->fmt_in.p_extra ); p_extra = ((uint8_t *)p_dec->fmt_in.p_extra) + p_dec->fmt_in.i_extra; *(p_extra++) = oggpacket.bytes >> 8; *(p_extra++) = oggpacket.bytes & 0xFF; @@ -392,8 +395,9 @@ static int ProcessHeaders( decoder_t *p_dec ) if( p_sys->b_packetizer ) { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; - p_dec->fmt_out.p_extra = - realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); + p_dec->fmt_out.p_extra = realloc_or_free( p_dec->fmt_out.p_extra, + p_dec->fmt_out.i_extra ); + assert( p_dec->fmt_out.p_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } @@ -530,6 +534,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket, i_pcm_output_size = p_sys->p_header->frame_size; p_frame_holder = (short*)malloc( sizeof(short)*i_pcm_output_size ); + assert( p_frame_holder ); speex_bits_read_from( &p_sys->bits, (char*)p_oggpacket->packet, p_oggpacket->bytes); @@ -1001,6 +1006,7 @@ static int OpenEncoder( vlc_object_t *p_this ) p_sys->i_frame_size = p_sys->i_frame_length * sizeof(int16_t) * p_enc->fmt_in.audio.i_channels; p_sys->p_buffer = malloc( p_sys->i_frame_size ); + assert( p_sys->p_buffer ); /* Create and store headers */ pp_header[0] = speex_header_to_packet( &p_sys->header, &pi_header[0] ); @@ -1009,6 +1015,7 @@ static int OpenEncoder( vlc_object_t *p_this ) p_enc->fmt_out.i_extra = 3 * 2 + pi_header[0] + pi_header[1]; p_extra = p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra ); + assert( p_extra ); for( i = 0; i < 2; i++ ) { *(p_extra++) = pi_header[i] >> 8; diff --git a/modules/codec/subtitles/subsdec.c b/modules/codec/subtitles/subsdec.c index e1d729cab4..d1b7572e44 100644 --- a/modules/codec/subtitles/subsdec.c +++ b/modules/codec/subtitles/subsdec.c @@ -31,6 +31,8 @@ # include "config.h" #endif +#include + #include "subsdec.h" #include @@ -458,6 +460,8 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block ) char *psz_convert_buffer_out = psz_new_subtitle; const char *psz_convert_buffer_in = psz_subtitle; + assert( psz_new_subtitle ); + size_t ret = vlc_iconv( p_sys->iconv_handle, &psz_convert_buffer_in, &inbytes_left, &psz_convert_buffer_out, &outbytes_left ); @@ -476,6 +480,8 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block ) psz_subtitle = realloc( psz_new_subtitle, psz_convert_buffer_out - psz_new_subtitle ); + if( !psz_subtitle ) + psz_subtitle = psz_new_subtitle; } } @@ -617,7 +623,8 @@ static char *StripTags( char *psz_subtitle ) psz_subtitle++; } *psz_text = '\0'; - psz_text_start = realloc( psz_text_start, strlen( psz_text_start ) + 1 ); + char *psz = realloc( psz_text_start, strlen( psz_text_start ) + 1 ); + if( psz ) psz_text_start = psz; return psz_text_start; } diff --git a/modules/codec/subtitles/subsusf.c b/modules/codec/subtitles/subsusf.c index 54b303194d..46db35323a 100644 --- a/modules/codec/subtitles/subsusf.c +++ b/modules/codec/subtitles/subsusf.c @@ -1085,7 +1085,9 @@ static char *StripTags( char *psz_subtitle ) psz_subtitle++; } *psz_text = '\0'; - psz_text_start = realloc( psz_text_start, strlen( psz_text_start ) + 1 ); + + char *psz = realloc( psz_text_start, strlen( psz_text_start ) + 1 ); + if( psz ) psz_text_start = psz; return psz_text_start; } diff --git a/modules/codec/theora.c b/modules/codec/theora.c index df5b4844df..8f5e328f02 100644 --- a/modules/codec/theora.c +++ b/modules/codec/theora.c @@ -28,11 +28,14 @@ # include "config.h" #endif +#include + #include #include #include #include #include +#include #include #include @@ -215,9 +218,9 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) /* Backup headers as extra data */ uint8_t *p_extra; - p_dec->fmt_in.p_extra = - realloc( p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra + - oggpacket.bytes + 2 ); + p_dec->fmt_in.p_extra = realloc_or_free( p_dec->fmt_in.p_extra, + p_dec->fmt_in.i_extra + oggpacket.bytes + 2 ); + assert( p_dec->fmt_in.p_extra ); p_extra = ((uint8_t *)p_dec->fmt_in.p_extra) + p_dec->fmt_in.i_extra; *(p_extra++) = oggpacket.bytes >> 8; *(p_extra++) = oggpacket.bytes & 0xFF; @@ -404,8 +407,9 @@ static int ProcessHeaders( decoder_t *p_dec ) else { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; - p_dec->fmt_out.p_extra = - realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); + p_dec->fmt_out.p_extra = realloc_or_free( p_dec->fmt_out.p_extra, + p_dec->fmt_out.i_extra ); + assert( p_dec->fmt_out.p_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } @@ -706,9 +710,9 @@ static int OpenEncoder( vlc_object_t *p_this ) else if( i == 1 ) theora_encode_comment( &p_sys->tc, &header ); else if( i == 2 ) theora_encode_tables( &p_sys->td, &header ); - p_enc->fmt_out.p_extra = - realloc( p_enc->fmt_out.p_extra, - p_enc->fmt_out.i_extra + header.bytes ); + p_enc->fmt_out.p_extra = realloc_or_free( p_enc->fmt_out.p_extra, + p_enc->fmt_out.i_extra + header.bytes ); + assert( p_enc->fmt_out.p_extra ); p_extra = p_enc->fmt_out.p_extra; p_extra += p_enc->fmt_out.i_extra + (i-3)*2; p_enc->fmt_out.i_extra += header.bytes; diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c index 03a3053cb3..d4598129c7 100644 --- a/modules/codec/vorbis.c +++ b/modules/codec/vorbis.c @@ -31,12 +31,15 @@ # include "config.h" #endif +#include + #include #include #include #include #include #include +#include #include @@ -318,9 +321,9 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) /* Backup headers as extra data */ uint8_t *p_extra; - p_dec->fmt_in.p_extra = - realloc( p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra + - oggpacket.bytes + 2 ); + p_dec->fmt_in.p_extra = realloc_or_free( p_dec->fmt_in.p_extra, + p_dec->fmt_in.i_extra + oggpacket.bytes + 2 ); + assert( p_dec->fmt_in.p_extra ); p_extra = (uint8_t *)p_dec->fmt_in.p_extra + p_dec->fmt_in.i_extra; *(p_extra++) = oggpacket.bytes >> 8; *(p_extra++) = oggpacket.bytes & 0xFF; @@ -454,8 +457,9 @@ static int ProcessHeaders( decoder_t *p_dec ) else { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; - p_dec->fmt_out.p_extra = - realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); + p_dec->fmt_out.p_extra = realloc_or_free( p_dec->fmt_out.p_extra, + p_dec->fmt_out.i_extra ); + assert( p_dec->fmt_out.p_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } @@ -879,6 +883,7 @@ static int OpenEncoder( vlc_object_t *p_this ) p_enc->fmt_out.i_extra = 3 * 2 + header[0].bytes + header[1].bytes + header[2].bytes; p_extra = p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra ); + assert( p_extra ); for( i = 0; i < 3; i++ ) { *(p_extra++) = header[i].bytes >> 8; diff --git a/modules/control/http/macro.c b/modules/control/http/macro.c index 4262d22f56..fb2802b706 100644 --- a/modules/control/http/macro.c +++ b/modules/control/http/macro.c @@ -26,9 +26,12 @@ # include "config.h" #endif +#include + #include "http.h" #include "macros.h" #include +#include static int MacroParse( macro_t *m, char *psz_src ) { @@ -149,7 +152,8 @@ static void MacroDo( httpd_file_sys_t *p_args, { \ int __i__ = *pp_dst - *pp_data; \ *pi_data += (l); \ - *pp_data = realloc( *pp_data, *pi_data ); \ + *pp_data = realloc_or_free( *pp_data, *pi_data ); \ + assert( *pp_data ); \ *pp_dst = (*pp_data) + __i__; \ } #define PRINT( str ) \ @@ -365,8 +369,9 @@ static void MacroDo( httpd_file_sys_t *p_args, if( !*item ) continue; int i_item = atoi( item ); - p_items = realloc( p_items, (i_nb_items + 1) * - sizeof(*p_items) ); + p_items = realloc_or_free( p_items, + (i_nb_items + 1) * sizeof(*p_items) ); + assert( p_items ); p_items[i_nb_items] = i_item; i_nb_items++; } @@ -402,8 +407,9 @@ static void MacroDo( httpd_file_sys_t *p_args, if( !*item ) continue; int i_item = atoi( item ); - p_items = realloc( p_items, (i_nb_items + 1) * - sizeof(*p_items) ); + p_items = realloc_or_free( p_items, + (i_nb_items + 1) * sizeof(*p_items) ); + assert( p_items ); p_items[i_nb_items] = i_item; i_nb_items++; } @@ -548,6 +554,8 @@ static void MacroDo( httpd_file_sys_t *p_args, char *vlm_error; int i; + assert( psz ); + if( p_intf->p_sys->p_vlm == NULL ) p_intf->p_sys->p_vlm = vlm_New( p_intf ); @@ -880,6 +888,8 @@ void Execute( httpd_file_sys_t *p_args, src = dup = malloc( _end - _src + 1 ); end = src +( _end - _src ); + assert( src ); + memcpy( src, _src, _end - _src ); *end = '\0'; @@ -1118,7 +1128,8 @@ void Execute( httpd_file_sys_t *p_args, int i_index = dst - *pp_data; *pi_data += i_copy; - *pp_data = realloc( *pp_data, *pi_data ); + *pp_data = realloc_or_free( *pp_data, *pi_data ); + assert( *pp_data ); dst = (*pp_data) + i_index; memcpy( dst, src, i_copy ); diff --git a/modules/control/http/mvar.c b/modules/control/http/mvar.c index 09d6ebd4d5..9e9deb9b1c 100644 --- a/modules/control/http/mvar.c +++ b/modules/control/http/mvar.c @@ -31,6 +31,8 @@ #include +#include + /* Utility function for scandir */ static int Filter( const char *foo ) { @@ -55,6 +57,7 @@ mvar_t *mvar_New( const char *name, const char *value ) v->i_field = 0; v->field = malloc( sizeof( mvar_t * ) ); + assert( v->field ); v->field[0] = NULL; return v; @@ -77,7 +80,9 @@ void mvar_Delete( mvar_t *v ) void mvar_AppendVar( mvar_t *v, mvar_t *f ) { - v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) ); + v->field = realloc_or_free( v->field, + sizeof( mvar_t * ) * ( v->i_field + 2 ) ); + assert( v->field ); v->field[v->i_field] = f; v->i_field++; } @@ -98,7 +103,9 @@ mvar_t *mvar_Duplicate( const mvar_t *v ) void mvar_PushVar( mvar_t *v, mvar_t *f ) { - v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) ); + v->field = realloc_or_free( v->field, + sizeof( mvar_t * ) * ( v->i_field + 2 ) ); + assert( v->field ); if( v->i_field > 0 ) { memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field ); diff --git a/modules/control/http/util.c b/modules/control/http/util.c index 1226002e20..70288be4e4 100644 --- a/modules/control/http/util.c +++ b/modules/control/http/util.c @@ -27,9 +27,12 @@ # include "config.h" #endif +#include + #include #include "http.h" #include +#include /**************************************************************************** * File and directory functions @@ -91,10 +94,13 @@ int FileLoad( FILE *f, char **pp_data, int *pi_data ) /* just load the file */ *pi_data = 0; *pp_data = malloc( 1025 ); /* +1 for \0 */ + assert( *pp_data ); + while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 ) { *pi_data += 1024; - *pp_data = realloc( *pp_data, *pi_data + 1025 ); + *pp_data = realloc_or_free( *pp_data, *pi_data + 1025 ); + assert( *pp_data ); } if( i_read > 0 ) { @@ -235,6 +241,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, f = malloc( sizeof( httpd_file_sys_t ) ); f->b_handler = false; } + assert( f ); f->p_intf = p_intf; f->p_file = NULL; @@ -921,6 +928,7 @@ char *RealPath( const char *psz_src ) int i_len = strlen(psz_src); psz_dir = malloc( i_len + 2 ); + assert( psz_dir ); strcpy( psz_dir, psz_src ); /* Add a trailing sep to ease the .. step */ diff --git a/modules/control/rc.c b/modules/control/rc.c index 2baa832c4b..cf69965ac6 100644 --- a/modules/control/rc.c +++ b/modules/control/rc.c @@ -30,8 +30,11 @@ # include "config.h" #endif +#include + #include #include +#include #include /* ENOMEM */ #include @@ -2106,7 +2109,9 @@ static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl ) else if( *psz_item ) { i_options++; - ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) ); + ppsz_options = realloc_or_free( ppsz_options, + i_options * sizeof(char *) ); + assert( ppsz_options ); ppsz_options[i_options - 1] = &psz_item[1]; } diff --git a/modules/control/telnet.c b/modules/control/telnet.c index ad7612390a..866200dca6 100644 --- a/modules/control/telnet.c +++ b/modules/control/telnet.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #include #include @@ -573,6 +576,7 @@ static char *MessageToString( vlm_message_t *message, int i_level ) i_message += strlen( message->psz_name ) + i_level * sizeof( " " ) + 1; psz_message = malloc( i_message ); + assert( psz_message ); *psz_message = 0; for( i = 0; i < i_level; i++ ) strcat( psz_message, " " ); strcat( psz_message, message->psz_name ); @@ -581,7 +585,8 @@ static char *MessageToString( vlm_message_t *message, int i_level ) { i_message += sizeof( " : " ) + strlen( message->psz_value ) + sizeof( STRING_CR ); - psz_message = realloc( psz_message, i_message ); + psz_message = realloc_or_free( psz_message, i_message ); + assert( psz_message ); strcat( psz_message, " : " ); strcat( psz_message, message->psz_value ); strcat( psz_message, STRING_CR ); @@ -589,7 +594,8 @@ static char *MessageToString( vlm_message_t *message, int i_level ) else { i_message += sizeof( STRING_CR ); - psz_message = realloc( psz_message, i_message ); + psz_message = realloc_or_free( psz_message, i_message ); + assert( psz_message ); strcat( psz_message, STRING_CR ); } @@ -599,7 +605,8 @@ static char *MessageToString( vlm_message_t *message, int i_level ) MessageToString( message->child[i], i_level + 1 ); i_message += strlen( child_message ); - psz_message = realloc( psz_message, i_message ); + psz_message = realloc_or_free( psz_message, i_message ); + assert( psz_message ); strcat( psz_message, child_message ); free( child_message ); } diff --git a/modules/demux/asademux.c b/modules/demux/asademux.c index 276d77cd3e..0739b58a76 100644 --- a/modules/demux/asademux.c +++ b/modules/demux/asademux.c @@ -35,9 +35,11 @@ #include #include #include +#include #include #include +#include #include "asademux.h" @@ -45,7 +47,7 @@ #define MAXGROUP 24 /**< maximum number of regex match groups */ #define xmalloc malloc -#define xrealloc realloc +#define xrealloc realloc_or_free #define xfree free #define xstrdup strdup @@ -247,6 +249,7 @@ static int asai_select (struct asa_import_state *state, if (state->selstr) xfree(state->selstr); state->selstr = xstrdup(state->matches[insn->v.select]); + assert(state->selstr); state->sellen = strlen(state->selstr); return 0; } @@ -262,6 +265,7 @@ static ptrdiff_t asai_process_replace(struct asa_import_state *state, newstr_size = v[0] * 2; newstr = (char *)xmalloc(newstr_size); + assert(newstr); memcpy(newstr, state->selstr, v[0]); newpos = v[0]; @@ -286,6 +290,7 @@ static ptrdiff_t asai_process_replace(struct asa_import_state *state, if (need > avail) { newstr_size += need - avail + 256; newstr = (char *)xrealloc(newstr, newstr_size); + assert(newstr); } memcpy(newstr + newpos, src, need); newpos += need; @@ -293,6 +298,7 @@ static ptrdiff_t asai_process_replace(struct asa_import_state *state, firstold = newpos; newstr_size = newpos + state->sellen - v[1]; newstr = (char *)xrealloc(newstr, newstr_size + 1); + assert(newstr); memcpy(newstr + newpos, state->selstr + v[1], state->sellen - v[1] + 1); state->selstr = newstr; @@ -352,6 +358,7 @@ static void asai_set_matches(struct asa_import_state *state, if (state->selstr) xfree(state->selstr); state->selstr = xstrdup(state->matches[0]); + assert(state->selstr); state->sellen = strlen(state->selstr); } @@ -383,6 +390,7 @@ static int asai_append (struct asa_import_state *state, { state->out = (char *)xrealloc(state->out, state->outlen + state->sellen + 1); + assert(state->out); memcpy(state->out + state->outlen, state->selstr, state->sellen); state->outlen += state->sellen; state->out[state->outlen] = '\0'; diff --git a/modules/demux/avi/avi.c b/modules/demux/avi/avi.c index 85db883507..9e530fcd3f 100644 --- a/modules/demux/avi/avi.c +++ b/modules/demux/avi/avi.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "libavi.h" @@ -2107,8 +2108,8 @@ static void AVI_IndexAddEntry( demux_sys_t *p_sys, if( tk->i_idxnb >= tk->i_idxmax ) { tk->i_idxmax += 16384; - tk->p_index = realloc( tk->p_index, - tk->i_idxmax * sizeof( avi_entry_t ) ); + tk->p_index = realloc_or_free( tk->p_index, + tk->i_idxmax * sizeof( avi_entry_t ) ); if( tk->p_index == NULL ) { return; diff --git a/modules/demux/gme.cpp b/modules/demux/gme.cpp index e24f04b9d0..d0ec1ce931 100644 --- a/modules/demux/gme.cpp +++ b/modules/demux/gme.cpp @@ -148,10 +148,12 @@ static int Open( vlc_object_t *p_this ) p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = (demux_sys_t *)malloc( sizeof( demux_sys_t ) ); + assert(p_sys); msg_Dbg( p_demux, "loading complete file (could be long)" ); p_sys->i_data = stream_Size( p_demux->s ); p_sys->p_data = (uint8_t *)malloc( p_sys->i_data ); + assert(p_sys->p_data); p_sys->i_data = stream_Read( p_demux->s, p_sys->p_data, p_sys->i_data ); if( p_sys->i_data <= 0 ) { @@ -455,6 +457,7 @@ switch( i_query ) *pi_int = p_sys->i_tracks; *ppp_title = (input_title_t**)malloc( sizeof( input_title_t**) * p_sys->i_tracks ); + assert( *ppp_sitle ); for( int i = 0; i < p_sys->i_tracks; i++ ) { @@ -499,6 +502,7 @@ static void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuff out_size = i_size * 2; out_buffer = (uint8_t*)malloc(out_size); + assert(out_buffer); z_str.next_in = (unsigned char*)p_buffer; z_str.avail_in = i_size; @@ -520,7 +524,8 @@ static void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuff case Z_BUF_ERROR: offset = z_str.next_out - out_buffer; out_size *= 2; - out_buffer = (uint8_t *)realloc(out_buffer, out_size); + out_buffer = (uint8_t *)realloc_or_free(out_buffer, out_size); + assert(out_buffer); z_str.next_out = out_buffer + offset; z_str.avail_out = out_size - offset; break; @@ -535,7 +540,8 @@ static void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuff inflateEnd(&z_str); - out_buffer = (uint8_t *)realloc(out_buffer, *pi_osize); + out_buffer = (uint8_t *)realloc_or_free(out_buffer, *pi_osize); + assert(out_buffer); (*pp_obuffer) = out_buffer; } #endif diff --git a/modules/demux/live555.cpp b/modules/demux/live555.cpp index 1183606993..cdf6adbe6b 100644 --- a/modules/demux/live555.cpp +++ b/modules/demux/live555.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -367,7 +368,8 @@ static int Open ( vlc_object_t *p_this ) } i_sdp_max += 1000; - p_sdp = (uint8_t*)realloc( p_sdp, i_sdp_max ); + p_sdp = (uint8_t*)realloc_or_free( p_sdp, i_sdp_max ); + assert( p_sdp ); } p_sys->p_sdp = (char*)p_sdp; } @@ -867,6 +869,7 @@ static int SessionsSetup( demux_t *p_demux ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); + assert( tk->fmt.p_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; } @@ -887,6 +890,7 @@ static int SessionsSetup( demux_t *p_demux ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); + assert( tk->fmt.p_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; } @@ -945,6 +949,7 @@ static int SessionsSetup( demux_t *p_demux ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); + assert( tk->fmt.p_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; @@ -966,6 +971,7 @@ static int SessionsSetup( demux_t *p_demux ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); + assert( tk->fmt.p_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; } @@ -1028,7 +1034,9 @@ static int SessionsSetup( demux_t *p_demux ) if( tk->p_es || tk->b_quicktime || tk->b_muxed || tk->b_asf ) { /* Append */ - p_sys->track = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) ); + p_sys->track = (live_track_t**)realloc_or_free( p_sys->track, + sizeof( live_track_t ) * ( p_sys->i_track + 1 ) ); + assert( p_sys->track ); p_sys->track[p_sys->i_track++] = tk; } else @@ -1618,6 +1626,7 @@ static void StreamRead( void *p_private, unsigned int i_size, { tk->fmt.i_extra = atomLength-8; tk->fmt.p_extra = malloc( tk->fmt.i_extra ); + assert( tk->fmt.p_extra ); memcpy(tk->fmt.p_extra, pos+8, atomLength-8); break; } @@ -1628,6 +1637,7 @@ static void StreamRead( void *p_private, unsigned int i_size, { tk->fmt.i_extra = qtState.sdAtomSize - 16; tk->fmt.p_extra = malloc( tk->fmt.i_extra ); + assert( tk->fmt.p_extra ); memcpy( tk->fmt.p_extra, &sdAtom[12], tk->fmt.i_extra ); } } diff --git a/modules/demux/mkv/chapters.cpp b/modules/demux/mkv/chapters.cpp index eb359baf78..2772f7060c 100644 --- a/modules/demux/mkv/chapters.cpp +++ b/modules/demux/mkv/chapters.cpp @@ -26,6 +26,9 @@ #include "chapter_command.hpp" +#include +#include + chapter_item_c::~chapter_item_c() { std::vector::iterator index = codecs.begin(); @@ -62,7 +65,9 @@ int chapter_item_c::PublishChapters( input_title_t & title, int & i_user_chapter // A start time of '0' is ok. A missing ChapterTime element is ok, too, because '0' is its default value. title.i_seekpoint++; - title.seekpoint = (seekpoint_t**)realloc( title.seekpoint, title.i_seekpoint * sizeof( seekpoint_t* ) ); + title.seekpoint = realloc_or_free( title.seekpoint, + title.i_seekpoint * sizeof( seekpoint_t* ) ); + assert( title.seekpoint ); title.seekpoint[title.i_seekpoint-1] = sk; if ( b_user_display ) diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp index 59dd144e60..67124c7f11 100644 --- a/modules/demux/mkv/matroska_segment.cpp +++ b/modules/demux/mkv/matroska_segment.cpp @@ -28,6 +28,9 @@ #include "demux.hpp" +#include +#include + extern "C" { #include "../vobsub.h" } @@ -179,7 +182,9 @@ void matroska_segment_c::LoadCues( KaxCues *cues ) if( i_index >= i_index_max ) { i_index_max += 1024; - p_indexes = (mkv_index_t*)realloc( p_indexes, sizeof( mkv_index_t ) * i_index_max ); + p_indexes = realloc_or_free( p_indexes, + sizeof( mkv_index_t ) * i_index_max ); + assert( p_indexes ); } #undef idx } @@ -372,7 +377,9 @@ void matroska_segment_c::IndexAppendCluster( KaxCluster *cluster ) if( i_index >= i_index_max ) { i_index_max += 1024; - p_indexes = (mkv_index_t*)realloc( p_indexes, sizeof( mkv_index_t ) * i_index_max ); + p_indexes = realloc_or_free( p_indexes, + sizeof( mkv_index_t ) * i_index_max ); + assert( p_indexes ); } #undef idx } @@ -665,6 +672,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) if( tracks[i_track]->fmt.i_extra > 0 ) { tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, &p_bih[1], tracks[i_track]->fmt.i_extra ); } } @@ -716,6 +724,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) if( i_size1 > 0 && i_size2 > 0 && i_size3 > 0 ) { tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); uint8_t *p_out = (uint8_t*)tracks[i_track]->fmt.p_extra; *p_out++ = (i_size1>>8) & 0xFF; *p_out++ = i_size1 & 0xFF; @@ -786,12 +795,14 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_codec = VLC_CODEC_MP4V; tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->i_extra_data ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data ); } } else if( !strcmp( tracks[i_track]->psz_codec, "V_QUICKTIME" ) ) { MP4_Box_t *p_box = (MP4_Box_t*)malloc( sizeof( MP4_Box_t ) ); + assert( p_box ); stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer), tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data, @@ -804,6 +815,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.video.i_height = p_box->data.p_sample_vide->i_height; tracks[i_track]->fmt.i_extra = p_box->data.p_sample_vide->i_qt_image_description; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, tracks[i_track]->fmt.i_extra ); MP4_FreeBox_sample_vide( p_box ); } @@ -836,6 +848,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) if( tracks[i_track]->fmt.i_extra > 0 ) { tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, &p_wf[1], tracks[i_track]->fmt.i_extra ); } } @@ -873,6 +886,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_codec = VLC_CODEC_FLAC; tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->i_extra_data ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data ); } else if( !strcmp( tracks[i_track]->psz_codec, "A_VORBIS" ) ) @@ -902,6 +916,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_extra = 3 * 2 + i_size[0] + i_size[1] + i_size[2]; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); p_extra = (uint8_t *)tracks[i_track]->fmt.p_extra; i_extra = 0; for( i = 0; i < 3; i++ ) { @@ -959,6 +974,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_extra = sbr ? 5 : 2; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); ((uint8_t*)tracks[i_track]->fmt.p_extra)[0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1); ((uint8_t*)tracks[i_track]->fmt.p_extra)[1] = ((i_srate & 0x1) << 7) | (tracks[i_track]->fmt.audio.i_channels << 3); if (sbr != 0) @@ -978,6 +994,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_codec = VLC_CODEC_MP4A; tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->i_extra_data ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data ); } else if( !strcmp( tracks[i_track]->psz_codec, "A_WAVPACK4" ) ) @@ -985,6 +1002,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_codec = VLC_CODEC_WAVPACK; tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->i_extra_data ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data ); } else if( !strcmp( tracks[i_track]->psz_codec, "A_TTA1" ) ) @@ -994,16 +1012,14 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) if( p_fmt->i_extra > 0 ) { p_fmt->p_extra = malloc( p_tk->i_extra_data ); - if( !p_fmt->p_extra ) - abort(); + assert( p_fmt->p_extra ); memcpy( p_fmt->p_extra, p_tk->p_extra_data, p_tk->i_extra_data ); } else { p_fmt->i_extra = 30; p_fmt->p_extra = malloc( p_fmt->i_extra ); - if( !p_fmt->p_extra ) - abort(); + assert( p_fmt->p_extra ); uint8_t *p_extra = (uint8_t*)p_fmt->p_extra; memcpy( &p_extra[ 0], "TTA1", 4 ); SetWLE( &p_extra[ 4], 1 ); @@ -1063,6 +1079,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) tracks[i_track]->fmt.i_extra = 1 + num_headers * 2 + size_so_far + pi_size[num_headers-1]; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra ); + assert( tracks[i_track]->fmt.p_extra ); p_extra = (uint8_t *)tracks[i_track]->fmt.p_extra; i_extra = 0; @@ -1097,6 +1114,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) { tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->i_extra_data ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data ); } } @@ -1111,6 +1129,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time ) { tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data; tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->i_extra_data ); + assert( tracks[i_track]->fmt.p_extra ); memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data ); } } diff --git a/modules/demux/nuv.c b/modules/demux/nuv.c index d32c6712a8..31abc9765d 100644 --- a/modules/demux/nuv.c +++ b/modules/demux/nuv.c @@ -32,6 +32,7 @@ #include #include #include +#include /* TODO: * - test @@ -923,8 +924,9 @@ static void demux_IndexAppend( demux_index_t *p_idx, else { p_idx->i_idx_max += 1000; - p_idx->idx = realloc( p_idx->idx, - p_idx->i_idx_max*sizeof(demux_index_entry_t)); + p_idx->idx = realloc_or_free( p_idx->idx, + p_idx->i_idx_max*sizeof(demux_index_entry_t)); + assert( p_idx->idx ); } } diff --git a/modules/demux/ogg.c b/modules/demux/ogg.c index c41c962756..71f5d601c5 100644 --- a/modules/demux/ogg.c +++ b/modules/demux/ogg.c @@ -671,7 +671,9 @@ static void Ogg_DecodePacket( demux_t *p_demux, p_stream->p_headers = realloc( p_sav = p_stream->p_headers, p_stream->i_headers + p_oggpacket->bytes + (b_store_size ? 2 : 0) + (b_store_num_headers ? 1 : 0) ); - if( p_stream->p_headers ) + if( !p_stream->p_headers ) + p_stream->p_headers = p_sav; + else { uint8_t *p_extra = p_stream->p_headers + p_stream->i_headers; @@ -714,10 +716,6 @@ static void Ogg_DecodePacket( demux_t *p_demux, p_ogg->i_bos--; } } - else - { - p_stream->p_headers = p_sav; - } b_selected = false; /* Discard the header packet */ } diff --git a/modules/demux/playlist/asx.c b/modules/demux/playlist/asx.c index 4f990706a9..b996b7e0e3 100644 --- a/modules/demux/playlist/asx.c +++ b/modules/demux/playlist/asx.c @@ -31,6 +31,8 @@ # include "config.h" #endif +#include + #include #include @@ -38,6 +40,7 @@ #include #include "playlist.h" #include +#include struct demux_sys_t { @@ -243,6 +246,7 @@ static int Demux( demux_t *p_demux ) p_sys->i_data_len = stream_Size( p_demux->s ) + 1; /* This is a cheat to prevent unnecessary realloc */ if( p_sys->i_data_len <= 0 || p_sys->i_data_len > 16384 ) p_sys->i_data_len = 1024; p_sys->psz_data = malloc( p_sys->i_data_len +1); + assert( p_sys->psz_data ); /* load the complete file */ for( ;; ) @@ -254,7 +258,9 @@ static int Demux( demux_t *p_demux ) i_pos += i_read; p_sys->i_data_len <<= 1 ; - p_sys->psz_data = realloc( p_sys->psz_data, p_sys->i_data_len * sizeof( char * ) + 1 ); + p_sys->psz_data = realloc_or_free( p_sys->psz_data, + p_sys->i_data_len * sizeof( char * ) + 1 ); + assert( p_sys->psz_data ); } if( p_sys->i_data_len <= 0 ) return -1; } @@ -313,6 +319,7 @@ static int Demux( demux_t *p_demux ) if( i_strlen < 1 ) continue; msg_Dbg( p_demux, "param name strlen: %d", i_strlen); psz_string = malloc( i_strlen + 1); + assert( psz_string ); memcpy( psz_string, psz_backup, i_strlen ); psz_string[i_strlen] = '\0'; msg_Dbg( p_demux, "param name: %s", psz_string); @@ -335,6 +342,7 @@ static int Demux( demux_t *p_demux ) if( i_strlen < 1 ) continue; msg_Dbg( p_demux, "param value strlen: %d", i_strlen); psz_string = malloc( i_strlen +1); + assert( psz_string ); memcpy( psz_string, psz_backup, i_strlen ); psz_string[i_strlen] = '\0'; msg_Dbg( p_demux, "param value: %s", psz_string); @@ -460,6 +468,7 @@ static int Demux( demux_t *p_demux ) i_strlen = psz_parse-psz_backup; if( i_strlen < 1 ) continue; psz_string = malloc( i_strlen +1); + assert( psz_string ); memcpy( psz_string, psz_backup, i_strlen ); psz_string[i_strlen] = '\0'; input_item_t *p_input; @@ -632,6 +641,7 @@ static int Demux( demux_t *p_demux ) free( psz_href ); psz_href = malloc( i_strlen +1); + assert( psz_string ); memcpy( psz_href, psz_backup, i_strlen ); psz_href[i_strlen] = '\0'; psz_tmp = psz_href + (i_strlen-1); diff --git a/modules/demux/ps.h b/modules/demux/ps.h index d456dfb0bb..a4e1760964 100644 --- a/modules/demux/ps.h +++ b/modules/demux/ps.h @@ -21,8 +21,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include #include +#include +#include /* 256-0xC0 for normal stream, 256 for 0xbd stream, 256 for 0xfd stream, 8 for 0xa0 AOB stream */ #define PS_TK_COUNT (256+256+256+8 - 0xc0) @@ -642,7 +643,7 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt, } } - tmp_es = realloc( p_psm->es, sizeof(ps_es_t *) * (p_psm->i_es+1) ); + tmp_es = realloc_or_free( p_psm->es, sizeof(ps_es_t *) * (p_psm->i_es+1) ); if( tmp_es ) { p_psm->es = tmp_es; diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c index 4faaa9cdcc..69e6978ba1 100644 --- a/modules/demux/subtitle.c +++ b/modules/demux/subtitle.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #ifdef HAVE_SYS_TYPES_H @@ -481,10 +482,9 @@ static int Open ( vlc_object_t *p_this ) if( p_sys->i_subtitles >= i_max ) { i_max += 500; - if( !( p_sys->subtitle = realloc( p_sys->subtitle, + if( !( p_sys->subtitle = realloc_or_free( p_sys->subtitle, sizeof(subtitle_t) * i_max ) ) ) { - free( p_sys->subtitle ); TextUnload( &p_sys->txt ); free( p_sys ); return VLC_ENOMEM; @@ -747,6 +747,8 @@ static int TextLoad( text_t *txt, stream_t *s ) txt->i_line_count = 0; txt->i_line = 0; txt->line = calloc( i_line_max, sizeof( char * ) ); + if( !txt->line ) + return VLC_ENOMEM; /* load the complete file */ for( ;; ) @@ -760,8 +762,11 @@ static int TextLoad( text_t *txt, stream_t *s ) if( txt->i_line_count >= i_line_max ) { i_line_max += 100; - txt->line = realloc( txt->line, i_line_max * sizeof( char * ) ); + txt->line = realloc_or_free( txt->line, i_line_max * sizeof( char * ) ); + if( !txt->line ) + return VLC_ENOMEM; } + free( psz ); } if( txt->i_line_count <= 0 ) @@ -928,7 +933,7 @@ static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle, } i_old = strlen( psz_text ); - psz_text = realloc( psz_text, i_old + i_len + 1 + 1 ); + psz_text = realloc_or_free( psz_text, i_old + i_len + 1 + 1 ); if( !psz_text ) { return VLC_ENOMEM; @@ -1061,9 +1066,9 @@ static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle, if( !p_sys->psz_header ) return VLC_ENOMEM; - p_sys->psz_header = - realloc( p_sys->psz_header, - strlen( p_sys->psz_header ) + strlen( s ) + 2 ); + p_sys->psz_header = realloc_or_free( p_sys->psz_header, + strlen( p_sys->psz_header ) + strlen( s ) + 2 ); + assert( p_sys->psz_header ); strcat( p_sys->psz_header, s ); strcat( p_sys->psz_header, "\n" ); } @@ -1295,7 +1300,7 @@ static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle, } i_old = strlen( psz_text ); - psz_text = realloc( psz_text, i_old + i_len + 1 + 1 ); + psz_text = realloc_or_free( psz_text, i_old + i_len + 1 + 1 ); if( !psz_text ) return VLC_ENOMEM; strcat( psz_text, s ); @@ -1402,7 +1407,7 @@ static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) else { i_old = strlen( psz_text ) + 1; - psz_text = realloc( psz_text, i_old + strlen( s ) + 1 ); + psz_text = realloc_or_free( psz_text, i_old + strlen( s ) + 1 ); if( !psz_text ) return VLC_ENOMEM; strcat( psz_text, s ); @@ -1548,7 +1553,7 @@ static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) int i_old = strlen( psz_text ); - psz_text = realloc( psz_text, i_old + i_len + 1 + 1 ); + psz_text = realloc_or_free( psz_text, i_old + i_len + 1 + 1 ); if( !psz_text ) return VLC_ENOMEM; @@ -1694,7 +1699,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) int i_old = strlen( psz_text ); - psz_text = realloc( psz_text, i_old + i_len + 1 ); + psz_text = realloc_or_free( psz_text, i_old + i_len + 1 ); if( !psz_text ) return VLC_ENOMEM; @@ -1714,6 +1719,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) /* Directives are NOT parsed yet */ /* This has probably a better place in a decoder ? */ /* directive = malloc( strlen( psz_text ) + 1 ); + assert( directive ); if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/ } @@ -1942,7 +1948,7 @@ static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) int i_old = strlen( psz_text ); - psz_text = realloc( psz_text, i_old + i_len + 1 + 1 ); + psz_text = realloc_or_free( psz_text, i_old + i_len + 1 + 1 ); if( !psz_text ) return VLC_ENOMEM; diff --git a/modules/demux/subtitle_asa.c b/modules/demux/subtitle_asa.c index 4882206a3c..381a4d20a2 100644 --- a/modules/demux/subtitle_asa.c +++ b/modules/demux/subtitle_asa.c @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -280,8 +281,8 @@ static int ProcessLine( demux_t *p_demux, void *p_arg, if( p_sys->i_subtitles >= p_sys->i_subs_alloc ) { p_sys->i_subs_alloc += 500; - if( !( p_sys->subtitle = realloc( p_sys->subtitle, sizeof(subtitle_t) - * p_sys->i_subs_alloc ) ) ) + if( !( p_sys->subtitle = realloc_or_free( p_sys->subtitle, + sizeof(subtitle_t) * p_sys->i_subs_alloc ) ) ) { return VLC_ENOMEM; } diff --git a/modules/demux/ts.c b/modules/demux/ts.c index 1a51259583..7745445179 100644 --- a/modules/demux/ts.c +++ b/modules/demux/ts.c @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -515,6 +516,10 @@ static int Open( vlc_object_t *p_this ) char *psz_event_text = malloc(130); char *psz_ext_text = malloc(1025); + assert( psz_name ); + assert( psz_event_text ); + assert( psz_ext_text ); + // 2 bytes version Uimsbf (4,5) // 2 bytes reserved (6,7) // 2 bytes duration in minutes Uimsbf (8,9( @@ -619,6 +624,7 @@ static int Open( vlc_object_t *p_this ) p_sys->i_ts_read = 1500 / p_sys->i_packet_size; } p_sys->buffer = malloc( p_sys->i_packet_size * p_sys->i_ts_read ); + assert( p_sys->buffer ); msg_Info( p_demux, "%s raw stream to file `%s' reading packets %d", b_append ? "appending" : "dumping", p_sys->psz_file, p_sys->i_ts_read ); @@ -3018,7 +3024,9 @@ static void EITCallBack( demux_t *p_demux, { msg_Dbg( p_demux, " - text='%s'", psz_text ); - psz_extra = realloc( psz_extra, strlen(psz_extra) + strlen(psz_text) + 1 ); + psz_extra = realloc_or_free( psz_extra, + strlen(psz_extra) + strlen(psz_text) + 1 ); + assert( psz_extra ); strcat( psz_extra, psz_text ); free( psz_text ); } @@ -3034,7 +3042,10 @@ static void EITCallBack( demux_t *p_demux, { msg_Dbg( p_demux, " - desc='%s' item='%s'", psz_dsc, psz_itm ); #if 0 - psz_extra = realloc( psz_extra, strlen(psz_extra) + strlen(psz_dsc) + strlen(psz_itm) + 3 + 1 ); + psz_extra = realloc_or_free( psz_extra, + strlen(psz_extra) + strlen(psz_dsc) + + strlen(psz_itm) + 3 + 1 ); + assert( psz_extra ); strcat( psz_extra, "(" ); strcat( psz_extra, psz_dsc ); strcat( psz_extra, " " ); diff --git a/modules/demux/vobsub.c b/modules/demux/vobsub.c index 97a7282093..4c12222e5b 100644 --- a/modules/demux/vobsub.c +++ b/modules/demux/vobsub.c @@ -29,8 +29,11 @@ # include "config.h" #endif +#include + #include #include +#include #include #include @@ -152,10 +155,12 @@ static int Open ( vlc_object_t *p_this ) p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); + assert( p_sys ); p_sys->i_length = 0; p_sys->p_vobsub_stream = NULL; p_sys->i_tracks = 0; p_sys->track = (vobsub_track_t *)malloc( sizeof( vobsub_track_t ) ); + assert( p_sys->track ); p_sys->i_original_frame_width = -1; p_sys->i_original_frame_height = -1; p_sys->b_palette = false; @@ -522,7 +527,9 @@ static int ParseVobSubIDX( demux_t *p_demux ) language, &i_track_id ) == 2 ) { p_sys->i_tracks++; - p_sys->track = realloc( p_sys->track, sizeof( vobsub_track_t ) * (p_sys->i_tracks + 1 ) ); + p_sys->track = realloc_or_free( p_sys->track, + sizeof( vobsub_track_t ) * (p_sys->i_tracks + 1 ) ); + assert( p_sys->track ); language[2] = '\0'; /* Init the track */ @@ -531,6 +538,7 @@ static int ParseVobSubIDX( demux_t *p_demux ) current_tk->i_current_subtitle = 0; current_tk->i_subtitles = 0; current_tk->p_subtitles = malloc( sizeof( subtitle_t ) );; + assert( current_tk->p_subtitles ); current_tk->i_track_id = i_track_id; current_tk->i_delay = (int64_t)0; @@ -581,7 +589,10 @@ static int ParseVobSubIDX( demux_t *p_demux ) i_location = loc; current_tk->i_subtitles++; - current_tk->p_subtitles = realloc( current_tk->p_subtitles, sizeof( subtitle_t ) * (current_tk->i_subtitles + 1 ) ); + current_tk->p_subtitles = + realloc_or_free( current_tk->p_subtitles, + sizeof( subtitle_t ) * (current_tk->i_subtitles + 1 ) ); + assert( current_tk->p_subtitles ); current_sub = ¤t_tk->p_subtitles[current_tk->i_subtitles - 1]; current_sub->i_start = i_start * i_sign; diff --git a/modules/gui/qnx/vout.c b/modules/gui/qnx/vout.c index ef775d1c28..e066d03fac 100644 --- a/modules/gui/qnx/vout.c +++ b/modules/gui/qnx/vout.c @@ -38,6 +38,7 @@ #include #include #include +#include /***************************************************************************** * vout_sys_t: video output QNX method descriptor @@ -316,16 +317,10 @@ static int QNXManage( vout_thread_t *p_vout ) if( i_ev == Ph_RESIZE_MSG ) { - PhEvent_t *buf; - i_buflen = PhGetMsgSize( p_event ); - buf = realloc( p_event, i_buflen ); - if( buf == NULL ) - { - free( p_event ); + p_event = realloc_or_free( p_event, i_buflen ); + if( p_event == NULL ) return( 1 ); - } - p_event = buf; } else if( i_ev == Ph_EVENT_MSG ) { diff --git a/modules/misc/freetype.c b/modules/misc/freetype.c index fb690fa7e2..e6090cac54 100644 --- a/modules/misc/freetype.c +++ b/modules/misc/freetype.c @@ -31,6 +31,8 @@ # include "config.h" #endif +#include + #include #include #include @@ -40,6 +42,7 @@ #include #include #include +#include #include #include @@ -360,6 +363,7 @@ static int Create( vlc_object_t *p_this ) * current contribs. So just tell default windows font directory * is the place to search fonts */ + assert( path ); GetWindowsDirectory( path, PATH_MAX + 1 ); strcat( path, "\\fonts" ); if( p_dialog ) @@ -1673,15 +1677,16 @@ static void SetupLine( filter_t *p_filter, const char *psz_text_in, { (*pi_runs)++; + /* XXX this logic looks somewhat broken */ + if( *ppp_styles ) { - *ppp_styles = (ft_style_t **) - realloc( *ppp_styles, *pi_runs * sizeof( ft_style_t * ) ); + *ppp_styles = realloc_or_free( *ppp_styles, + *pi_runs * sizeof( ft_style_t * ) ); } else if( *pi_runs == 1 ) { - *ppp_styles = (ft_style_t **) - malloc( *pi_runs * sizeof( ft_style_t * ) ); + *ppp_styles = malloc( *pi_runs * sizeof( ft_style_t * ) ); } /* We have just malloc'ed this memory successfully - @@ -1692,10 +1697,12 @@ static void SetupLine( filter_t *p_filter, const char *psz_text_in, p_style = NULL; } + /* XXX more iffy logic */ + if( *ppi_run_lengths ) { - *ppi_run_lengths = (uint32_t *) - realloc( *ppi_run_lengths, *pi_runs * sizeof( uint32_t ) ); + *ppi_run_lengths = realloc_or_free( *ppi_run_lengths, + *pi_runs * sizeof( uint32_t ) ); } else if( *pi_runs == 1 ) { diff --git a/modules/misc/text_renderer.h b/modules/misc/text_renderer.h index cddaab7127..dc0f35496f 100644 --- a/modules/misc/text_renderer.h +++ b/modules/misc/text_renderer.h @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#include + typedef struct font_stack_t font_stack_t; struct font_stack_t { @@ -442,8 +444,7 @@ static void SetupKaraoke( xml_reader_t *p_xml_reader, uint32_t *pi_k_runs, if( *ppi_k_durations ) { - *ppi_k_durations = (uint32_t *) - realloc( *ppi_k_durations, + *ppi_k_durations = realloc_or_free( *ppi_k_durations, *pi_k_runs * sizeof( uint32_t ) ); } else if( *pi_k_runs == 1 ) @@ -454,8 +455,7 @@ static void SetupKaraoke( xml_reader_t *p_xml_reader, uint32_t *pi_k_runs, if( *ppi_k_run_lengths ) { - *ppi_k_run_lengths = (uint32_t *) - realloc( *ppi_k_run_lengths, + *ppi_k_run_lengths = realloc_or_free( *ppi_k_run_lengths, *pi_k_runs * sizeof( uint32_t ) ); } else if( *pi_k_runs == 1 ) diff --git a/modules/misc/xml/xtag.c b/modules/misc/xml/xtag.c index 668fd80b78..de4b6ea82f 100644 --- a/modules/misc/xml/xtag.c +++ b/modules/misc/xml/xtag.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -174,7 +175,7 @@ static void CatalogAdd( xml_t *p_xml, const char *psz_arg1, static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *s ) { xml_reader_t *p_reader; - char *p_buffer, *p_new; + char *p_buffer; int i_size, i_pos = 0, i_buffer = 2048; XTag *p_root; @@ -187,13 +188,9 @@ static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *s ) { i_pos += i_size; i_buffer += i_size; - p_new = realloc( p_buffer, i_buffer ); - if( !p_new ) - { - free( p_buffer ); + p_buffer = realloc_or_free( p_buffer, i_buffer ); + if( !p_buffer ) return NULL; - } - p_buffer = p_new; } if( i_pos + i_size == 0 ) { @@ -355,6 +352,7 @@ static XList *xlist_append( XList *list, void *data ) XList *l, *last; l = (XList *)malloc( sizeof(XList) ); + assert( l ); l->prev = l->next = NULL; l->data = data; @@ -460,6 +458,7 @@ static char *xtag_slurp_to( XTagParser *parser, int good_end, int bad_end ) if( xi > 0 && xtag_cin (s[xi], good_end) ) { ret = malloc( xi+1 ); + assert( ret ); strncpy( ret, s, xi ); ret[xi] = '\0'; parser->start = &s[xi]; @@ -513,6 +512,7 @@ static char *xtag_slurp_quoted( XTagParser *parser ) } ret = malloc( xi+1 ); + assert( ret ); strncpy( ret, s, xi ); ret[xi] = '\0'; parser->start = &s[xi]; @@ -565,6 +565,7 @@ static XAttribute *xtag_parse_attribute( XTagParser *parser ) } attr = malloc( sizeof (*attr) ); + assert( attr ); attr->name = name; attr->value = value; return attr; @@ -639,6 +640,7 @@ static XTag *xtag_parse_tag( XTagParser *parser ) if( (pcdata = xtag_slurp_to( parser, X_OPENTAG, X_NONE )) != NULL ) { tag = malloc( sizeof(*tag) ); + assert( tag ); tag->name = NULL; tag->pcdata = pcdata; tag->parent = parser->current_tag; @@ -693,6 +695,7 @@ static XTag *xtag_parse_tag( XTagParser *parser ) #endif tag = malloc( sizeof(*tag) ); + assert( tag ); tag->name = name; tag->pcdata = NULL; tag->parent = parser->current_tag; @@ -832,6 +835,7 @@ static XTag *xtag_new_parse( const char *s, int n ) } wrapper = malloc( sizeof(XTag) ); + assert( wrapper ); wrapper->name = NULL; wrapper->pcdata = NULL; wrapper->parent = NULL; diff --git a/modules/mux/avi.c b/modules/mux/avi.c index da6556ddb6..31e6504998 100644 --- a/modules/mux/avi.c +++ b/modules/mux/avi.c @@ -31,11 +31,14 @@ # include "config.h" #endif +#include + #include #include #include #include #include +#include /***************************************************************************** * Module descriptor @@ -482,8 +485,9 @@ static int Mux ( sout_mux_t *p_mux ) if( p_sys->idx1.i_entry_count >= p_sys->idx1.i_entry_max ) { p_sys->idx1.i_entry_max += 10000; - p_sys->idx1.entry = realloc( p_sys->idx1.entry, - p_sys->idx1.i_entry_max * sizeof( avi_idx1_entry_t ) ); + p_sys->idx1.entry = realloc_or_free( p_sys->idx1.entry, + p_sys->idx1.i_entry_max * sizeof( avi_idx1_entry_t ) ); + assert( p_sys->idx1.entry ); } p_data = block_Realloc( p_data, 8, p_data->i_buffer ); diff --git a/modules/mux/mp4.c b/modules/mux/mp4.c index d59c90d706..13e72fa290 100644 --- a/modules/mux/mp4.c +++ b/modules/mux/mp4.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #include @@ -597,9 +600,9 @@ again: if( p_stream->i_entry_count >= p_stream->i_entry_max - 1 ) { p_stream->i_entry_max += 1000; - p_stream->entry = - realloc( p_stream->entry, + p_stream->entry = realloc_or_free( p_stream->entry, p_stream->i_entry_max * sizeof( mp4_entry_t ) ); + assert( p_stream->entry ); } /* update */ @@ -1948,6 +1951,7 @@ static void bo_init( bo_t *p_bo, int i_size, uint8_t *p_buffer, { p_bo->i_buffer_size = __MAX( i_size, 1024 ); p_bo->p_buffer = malloc( p_bo->i_buffer_size ); + assert( p_bo->p_buffer ); } else { @@ -1968,8 +1972,8 @@ static void bo_add_8( bo_t *p_bo, uint8_t i ) else if( p_bo->b_grow ) { p_bo->i_buffer_size += 1024; - p_bo->p_buffer = realloc( p_bo->p_buffer, p_bo->i_buffer_size ); - + p_bo->p_buffer = realloc_or_free( p_bo->p_buffer, p_bo->i_buffer_size ); + assert( p_bo->p_buffer ); p_bo->p_buffer[p_bo->i_buffer] = i; } diff --git a/modules/mux/ogg.c b/modules/mux/ogg.c index 7528059455..233c99714d 100644 --- a/modules/mux/ogg.c +++ b/modules/mux/ogg.c @@ -30,11 +30,14 @@ # include "config.h" #endif +#include + #include #include #include #include #include +#include #include @@ -535,9 +538,9 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input ) /* move input in delete queue */ if( !p_stream->b_new ) { - p_sys->pp_del_streams = realloc( p_sys->pp_del_streams, - (p_sys->i_del_streams + 1) * - sizeof(ogg_stream_t *) ); + p_sys->pp_del_streams = realloc_or_free( p_sys->pp_del_streams, + (p_sys->i_del_streams + 1) * sizeof(ogg_stream_t *) ); + assert( p_sys->pp_del_streams ); p_sys->pp_del_streams[p_sys->i_del_streams++] = p_stream; } else diff --git a/modules/packetizer/mpeg4video.c b/modules/packetizer/mpeg4video.c index 7497c7cf63..91970408d7 100644 --- a/modules/packetizer/mpeg4video.c +++ b/modules/packetizer/mpeg4video.c @@ -31,11 +31,14 @@ # include "config.h" #endif +#include + #include #include #include #include #include +#include #include #include @@ -157,6 +160,7 @@ static int Open( vlc_object_t *p_this ) /* We have a vol */ p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra ); + assert( p_dec->fmt_out.p_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra ); @@ -287,7 +291,8 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) if( (size_t)p_dec->fmt_out.i_extra != p_frag->i_buffer ) { p_dec->fmt_out.p_extra = - realloc( p_dec->fmt_out.p_extra, p_frag->i_buffer ); + realloc_or_free( p_dec->fmt_out.p_extra, p_frag->i_buffer ); + assert( p_dec->fmt_out.p_extra ); p_dec->fmt_out.i_extra = p_frag->i_buffer; } memcpy( p_dec->fmt_out.p_extra, p_frag->p_buffer, p_frag->i_buffer ); diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c index 9651bae992..7cbc47dc6a 100644 --- a/modules/packetizer/vc1.c +++ b/modules/packetizer/vc1.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include #include #include @@ -138,6 +141,7 @@ static int Open( vlc_object_t *p_this ) /* Create the output format */ es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) ); + assert( p_sys ); packetizer_Init( &p_sys->packetizer, p_vc1_startcode, sizeof(p_vc1_startcode), @@ -309,7 +313,8 @@ static void BuildExtraData( decoder_t *p_dec ) if( p_es->i_extra != i_extra ) { p_es->i_extra = i_extra; - p_es->p_extra = realloc( p_dec->fmt_out.p_extra, p_es->i_extra ); + p_es->p_extra = realloc_or_free( p_es->p_extra, p_es->i_extra ); + assert( p_es->p_extra ); } memcpy( p_es->p_extra, p_sys->sh.p_sh->p_buffer, p_sys->sh.p_sh->i_buffer ); diff --git a/modules/services_discovery/sap.c b/modules/services_discovery/sap.c index eefd8930a7..60e45591bc 100644 --- a/modules/services_discovery/sap.c +++ b/modules/services_discovery/sap.c @@ -414,6 +414,7 @@ static int OpenDemux( vlc_object_t *p_this ) if( p_sdp->psz_uri == NULL ) goto error; p_demux->p_sys = (demux_sys_t *)malloc( sizeof(demux_sys_t) ); + assert( p_demux->p_sys ); p_demux->p_sys->p_sdp = p_sdp; p_demux->pf_control = Control; p_demux->pf_demux = Demux; diff --git a/modules/stream_out/bridge.c b/modules/stream_out/bridge.c index 8a67575027..127634c4c1 100644 --- a/modules/stream_out/bridge.c +++ b/modules/stream_out/bridge.c @@ -30,10 +30,13 @@ # include "config.h" #endif +#include + #include #include #include #include +#include /***************************************************************************** * Module descriptor @@ -195,6 +198,7 @@ static int OpenOut( vlc_object_t *p_this ) p_stream->p_cfg ); p_sys = malloc( sizeof( out_sout_stream_sys_t ) ); + assert( p_sys ); p_sys->b_inited = false; var_Create( p_this->p_libvlc, "bridge-lock", VLC_VAR_MUTEX ); @@ -258,6 +262,7 @@ static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt ) if ( p_bridge == NULL ) { p_bridge = malloc( sizeof( bridge_t ) ); + assert( p_bridge ); var_Create( p_stream->p_libvlc, p_sys->psz_name, VLC_VAR_ADDRESS ); var_SetAddress( p_stream->p_libvlc, p_sys->psz_name, p_bridge ); @@ -274,11 +279,12 @@ static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt ) if ( i == p_bridge->i_es_num ) { - p_bridge->pp_es = realloc( p_bridge->pp_es, - (p_bridge->i_es_num + 1) - * sizeof(bridged_es_t *) ); + p_bridge->pp_es = realloc_or_free( p_bridge->pp_es, + (p_bridge->i_es_num + 1) * sizeof(bridged_es_t *) ); + assert( p_bridge->pp_es ); p_bridge->i_es_num++; p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) ); + assert( p_bridge->pp_es[i] ); } p_sys->p_es = p_es = p_bridge->pp_es[i]; @@ -391,6 +397,7 @@ static int OpenIn( vlc_object_t *p_this ) vlc_value_t val; p_sys = malloc( sizeof( in_sout_stream_sys_t ) ); + assert( p_sys ); p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next ); if( !p_sys->p_out ) diff --git a/modules/stream_out/mosaic_bridge.c b/modules/stream_out/mosaic_bridge.c index 30aab1aab0..78117fef73 100644 --- a/modules/stream_out/mosaic_bridge.c +++ b/modules/stream_out/mosaic_bridge.c @@ -42,6 +42,8 @@ #include #include +#include + #include "../video_filter/mosaic.h" #include @@ -362,6 +364,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) vlc_value_t val; p_bridge = malloc( sizeof( bridge_t ) ); + assert( p_bridge ); var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS ); val.p_address = p_bridge; @@ -379,11 +382,12 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) if ( i == p_bridge->i_es_num ) { - p_bridge->pp_es = realloc( p_bridge->pp_es, - (p_bridge->i_es_num + 1) - * sizeof(bridged_es_t *) ); + p_bridge->pp_es = realloc_or_free( p_bridge->pp_es, + (p_bridge->i_es_num + 1) * sizeof(bridged_es_t *) ); + assert( p_bridge->pp_es ); p_bridge->i_es_num++; p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) ); + assert( p_bridge->pp_es[i] ); } p_sys->p_es = p_es = p_bridge->pp_es[i]; diff --git a/modules/stream_out/raop.c b/modules/stream_out/raop.c index f4cf3c4808..70a4e37868 100644 --- a/modules/stream_out/raop.c +++ b/modules/stream_out/raop.c @@ -42,6 +42,7 @@ #include #include #include +#include #define RAOP_PORT 5000 #define RAOP_USER_AGENT "VLC " VERSION @@ -1299,7 +1300,7 @@ static void SendAudio( sout_stream_t *p_stream, block_t *p_buffer ) /* Grow in blocks of 4K */ i_realloc_len = (1 + (i_len / 4096)) * 4096; - p_sys->p_sendbuf = realloc( p_sys->p_sendbuf, i_realloc_len ); + p_sys->p_sendbuf = realloc_or_free( p_sys->p_sendbuf, i_realloc_len ); if ( p_sys->p_sendbuf == NULL ) goto error; diff --git a/modules/video_filter/audiobargraph_v.c b/modules/video_filter/audiobargraph_v.c index 269fed2cc2..2ca709a30a 100644 --- a/modules/video_filter/audiobargraph_v.c +++ b/modules/video_filter/audiobargraph_v.c @@ -38,6 +38,8 @@ #include #include +#include + #ifdef LoadImage # undef LoadImage #endif @@ -940,7 +942,9 @@ void parse_i_values( BarGraph_t *p_BarGraph, char *i_values) res = strtok_r(i_values, delim, &tok); while (res != NULL) { p_BarGraph->nbChannels++; - p_BarGraph->i_values = (int*)realloc(p_BarGraph->i_values, p_BarGraph->nbChannels*sizeof(int)); + p_BarGraph->i_values = realloc_or_free(p_BarGraph->i_values, + p_BarGraph->nbChannels*sizeof(int)); + assert(p_BarGraph->i_values); p_BarGraph->i_values[p_BarGraph->nbChannels-1] = __MAX( __MIN( atof(res)*p_BarGraph->scale, p_BarGraph->scale ), 0 ); res = strtok_r(NULL, delim, &tok); } diff --git a/modules/video_filter/bluescreen.c b/modules/video_filter/bluescreen.c index 5753429803..d889b540c9 100644 --- a/modules/video_filter/bluescreen.c +++ b/modules/video_filter/bluescreen.c @@ -29,9 +29,12 @@ # include "config.h" #endif +#include + #include #include #include +#include #define BLUESCREEN_HELP N_( \ "This effect, also known as \"greenscreen\" or \"chroma key\" blends " \ @@ -185,7 +188,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) return NULL; } - p_sys->p_at = realloc( p_sys->p_at, i_lines * i_pitch * sizeof( uint8_t ) ); + p_sys->p_at = realloc_or_free( p_sys->p_at, + i_lines * i_pitch * sizeof( uint8_t ) ); + assert( p_sys->p_at ); p_at = p_sys->p_at; vlc_mutex_lock( &p_sys->lock ); diff --git a/modules/video_filter/dynamicoverlay/dynamicoverlay_list.c b/modules/video_filter/dynamicoverlay/dynamicoverlay_list.c index 477815a6df..06d4170c87 100644 --- a/modules/video_filter/dynamicoverlay/dynamicoverlay_list.c +++ b/modules/video_filter/dynamicoverlay/dynamicoverlay_list.c @@ -28,6 +28,7 @@ #include #include +#include #include #include "dynamicoverlay.h" @@ -80,8 +81,8 @@ ssize_t ListAdd( list_t *p_list, overlay_t *p_new ) /* Have to expand */ size_t i_size = p_list->pp_tail - p_list->pp_head; size_t i_newsize = i_size * 2; - p_list->pp_head = realloc( p_list->pp_head, - i_newsize * sizeof( overlay_t * ) ); + p_list->pp_head = realloc_or_free( p_list->pp_head, + i_newsize * sizeof( overlay_t * ) ); if( p_list->pp_head == NULL ) return VLC_ENOMEM; diff --git a/modules/video_filter/gaussianblur.c b/modules/video_filter/gaussianblur.c index daee2a115d..48dc7f96fe 100644 --- a/modules/video_filter/gaussianblur.c +++ b/modules/video_filter/gaussianblur.c @@ -29,8 +29,11 @@ # include "config.h" #endif +#include + #include #include +#include #include #include "filter_picture.h" @@ -102,6 +105,8 @@ static void gaussianblur_InitDistribution( filter_sys_t *p_sys ) type_t *pt_distribution = malloc( (2*i_dim+1) * sizeof( type_t ) ); int x; + assert( pt_distribution ); + for( x = -i_dim; x <= i_dim; x++ ) { const float f_distribution = sqrt( exp(-(x*x)/(f_sigma*f_sigma) ) / (2.*M_PI*f_sigma*f_sigma) ); @@ -199,10 +204,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) } if( !p_sys->pt_buffer ) { - p_sys->pt_buffer = realloc( p_sys->pt_buffer, - p_pic->p[Y_PLANE].i_visible_lines * - p_pic->p[Y_PLANE].i_pitch * - sizeof( type_t ) ); + p_sys->pt_buffer = realloc_or_free( p_sys->pt_buffer, + p_pic->p[Y_PLANE].i_visible_lines * + p_pic->p[Y_PLANE].i_pitch * sizeof( type_t ) ); } pt_buffer = p_sys->pt_buffer; @@ -215,6 +219,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) p_sys->pt_scale = malloc( i_visible_lines * i_pitch * sizeof( type_t ) ); pt_scale = p_sys->pt_scale; + assert( pt_scale ); for( i_line = 0 ; i_line < i_visible_lines ; i_line++ ) { diff --git a/modules/video_filter/mosaic.c b/modules/video_filter/mosaic.c index 1100d22751..ea47c41eec 100644 --- a/modules/video_filter/mosaic.c +++ b/modules/video_filter/mosaic.c @@ -34,10 +34,13 @@ #include #include /* INT_MAX */ +#include #include #include +#include + #include "mosaic.h" #define BLANK_DELAY INT64_C(1000000) @@ -254,14 +257,16 @@ static void __mosaic_ParseSetOffsets( vlc_object_t *p_this, { i_index++; - p_sys->pi_x_offsets = - realloc( p_sys->pi_x_offsets, i_index * sizeof(int) ); + p_sys->pi_x_offsets = realloc_or_free( p_sys->pi_x_offsets, + i_index * sizeof(int) ); + assert( p_sys->pi_x_offsets ); p_sys->pi_x_offsets[i_index - 1] = atoi( psz_offsets ); psz_end = strchr( psz_offsets, ',' ); psz_offsets = psz_end + 1; - p_sys->pi_y_offsets = - realloc( p_sys->pi_y_offsets, i_index * sizeof(int) ); + p_sys->pi_y_offsets = realloc_or_free( p_sys->pi_y_offsets, + i_index * sizeof(int) ); + assert( p_sys->pi_y_offsets ); p_sys->pi_y_offsets[i_index - 1] = atoi( psz_offsets ); psz_end = strchr( psz_offsets, ',' ); psz_offsets = psz_end + 1; @@ -359,8 +364,9 @@ static int CreateFilter( vlc_object_t *p_this ) { psz_end = strchr( psz_order, ',' ); i_index++; - p_sys->ppsz_order = realloc( p_sys->ppsz_order, - i_index * sizeof(char *) ); + p_sys->ppsz_order = realloc_or_free( p_sys->ppsz_order, + i_index * sizeof(char *) ); + assert( p_sys->ppsz_order ); p_sys->ppsz_order[i_index - 1] = strndup( psz_order, psz_end - psz_order ); psz_order = psz_end+1; @@ -876,8 +882,9 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var, { psz_end = strchr( psz_order, ',' ); i_index++; - p_sys->ppsz_order = realloc( p_sys->ppsz_order, - i_index * sizeof(char *) ); + p_sys->ppsz_order = realloc_or_free( p_sys->ppsz_order, + i_index * sizeof(char *) ); + assert( p_sys->ppsz_order ); p_sys->ppsz_order[i_index - 1] = strndup( psz_order, psz_end - psz_order ); psz_order = psz_end+1; diff --git a/modules/video_filter/rss.c b/modules/video_filter/rss.c index 98164fc0c3..b9a080b7af 100644 --- a/modules/video_filter/rss.c +++ b/modules/video_filter/rss.c @@ -35,6 +35,8 @@ # include "config.h" #endif +#include + #include #include @@ -48,6 +50,8 @@ #include +#include + #include /***************************************************************************** @@ -706,8 +710,9 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader, { b_is_item = true; p_feed->i_items++; - p_feed->p_items = realloc( p_feed->p_items, - p_feed->i_items * sizeof( rss_item_t ) ); + p_feed->p_items = realloc_or_free( p_feed->p_items, + p_feed->i_items * sizeof( rss_item_t ) ); + assert( p_feed->p_items ); p_feed->p_items[p_feed->i_items-1].psz_title = NULL; p_feed->p_items[p_feed->i_items-1].psz_description = NULL; p_feed->p_items[p_feed->i_items-1].psz_link = NULL; diff --git a/modules/video_output/msw/directx.c b/modules/video_output/msw/directx.c index 678e7e7e40..c2a1fa552c 100644 --- a/modules/video_output/msw/directx.c +++ b/modules/video_output/msw/directx.c @@ -42,6 +42,7 @@ #include #include #include /* needed for wallpaper */ +#include #include #include /* ListView_(Get|Set)* */ @@ -1817,12 +1818,12 @@ BOOL WINAPI DirectXEnumCallback2( GUID* p_guid, LPTSTR psz_desc, module_config_t *p_item = (module_config_t *)p_context; - p_item->ppsz_list = - (char **)realloc( p_item->ppsz_list, + p_item->ppsz_list = realloc_or_free( p_item->ppsz_list, (p_item->i_list+2) * sizeof(char *) ); - p_item->ppsz_list_text = - (char **)realloc( p_item->ppsz_list_text, + assert( p_item->ppsz_list ); + p_item->ppsz_list_text = realloc_or_free( p_item->ppsz_list_text, (p_item->i_list+2) * sizeof(char *) ); + assert( p_item->ppsz_list_text ); p_item->ppsz_list[p_item->i_list] = strdup( psz_drivername ); p_item->ppsz_list_text[p_item->i_list] = NULL; -- 2.39.2