Commit 4e472031 authored by JP Dinger's avatar JP Dinger

Introduce realloc_or_free() to src/*, and add assert() to mark unhandled...

Introduce realloc_or_free() to src/*, and add assert() to mark unhandled ENOMEM error conditions. Allocation shrinking or otherwise handled allocations don't need realloc_or_free.
parent f7600a71
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#ifndef _LIBVLC_MEDIA_LIST_PATH_H #ifndef _LIBVLC_MEDIA_LIST_PATH_H
#define _LIBVLC_MEDIA_LIST_PATH_H 1 #define _LIBVLC_MEDIA_LIST_PATH_H 1
#include <assert.h>
#include <vlc_memory.h>
typedef int * libvlc_media_list_path_t; /* (Media List Player Internal) */ typedef int * libvlc_media_list_path_t; /* (Media List Player Internal) */
/************************************************************************** /**************************************************************************
...@@ -50,6 +53,7 @@ static inline void libvlc_media_list_path_dump( const libvlc_media_list_path_t p ...@@ -50,6 +53,7 @@ static inline void libvlc_media_list_path_dump( const libvlc_media_list_path_t p
static inline libvlc_media_list_path_t libvlc_media_list_path_empty( void ) static inline libvlc_media_list_path_t libvlc_media_list_path_empty( void )
{ {
libvlc_media_list_path_t ret = malloc(sizeof(int)); libvlc_media_list_path_t ret = malloc(sizeof(int));
assert( ret );
ret[0] = -1; ret[0] = -1;
return ret; return ret;
} }
...@@ -60,6 +64,7 @@ static inline libvlc_media_list_path_t libvlc_media_list_path_empty( void ) ...@@ -60,6 +64,7 @@ static inline libvlc_media_list_path_t libvlc_media_list_path_empty( void )
static inline libvlc_media_list_path_t libvlc_media_list_path_with_root_index( int index ) static inline libvlc_media_list_path_t libvlc_media_list_path_with_root_index( int index )
{ {
libvlc_media_list_path_t ret = malloc(sizeof(int)*2); libvlc_media_list_path_t ret = malloc(sizeof(int)*2);
assert( ret );
ret[0] = index; ret[0] = index;
ret[1] = -1; ret[1] = -1;
return ret; return ret;
...@@ -81,7 +86,8 @@ static inline int libvlc_media_list_path_depth( const libvlc_media_list_path_t p ...@@ -81,7 +86,8 @@ static inline int libvlc_media_list_path_depth( const libvlc_media_list_path_t p
static inline void libvlc_media_list_path_append( libvlc_media_list_path_t * p_path, int index ) static inline void libvlc_media_list_path_append( libvlc_media_list_path_t * p_path, int index )
{ {
int old_depth = libvlc_media_list_path_depth( *p_path ); int old_depth = libvlc_media_list_path_depth( *p_path );
*p_path = realloc( *p_path, sizeof(int)*(old_depth+2)); *p_path = realloc_or_free( *p_path, sizeof(int)*(old_depth+2));
assert( *p_path );
*p_path[old_depth] = index; *p_path[old_depth] = index;
*p_path[old_depth+1] = -1; *p_path[old_depth+1] = -1;
} }
...@@ -94,6 +100,7 @@ static inline libvlc_media_list_path_t libvlc_media_list_path_copy_by_appending( ...@@ -94,6 +100,7 @@ static inline libvlc_media_list_path_t libvlc_media_list_path_copy_by_appending(
libvlc_media_list_path_t ret; libvlc_media_list_path_t ret;
int old_depth = libvlc_media_list_path_depth( path ); int old_depth = libvlc_media_list_path_depth( path );
ret = malloc( sizeof(int) * (old_depth + 2) ); ret = malloc( sizeof(int) * (old_depth + 2) );
assert( ret );
memcpy( ret, path, sizeof(int) * old_depth ); memcpy( ret, path, sizeof(int) * old_depth );
ret[old_depth] = index; ret[old_depth] = index;
ret[old_depth+1] = -1; ret[old_depth+1] = -1;
...@@ -108,6 +115,7 @@ static inline libvlc_media_list_path_t libvlc_media_list_path_copy( const libvlc ...@@ -108,6 +115,7 @@ static inline libvlc_media_list_path_t libvlc_media_list_path_copy( const libvlc
libvlc_media_list_path_t ret; libvlc_media_list_path_t ret;
int depth = libvlc_media_list_path_depth( path ); int depth = libvlc_media_list_path_depth( path );
ret = malloc( sizeof(int)*(depth+1) ); ret = malloc( sizeof(int)*(depth+1) );
assert( ret );
memcpy( ret, path, sizeof(int)*(depth+1) ); memcpy( ret, path, sizeof(int)*(depth+1) );
return ret; return ret;
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_memory.h>
#include <ctype.h> #include <ctype.h>
...@@ -865,7 +866,8 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv, ...@@ -865,7 +866,8 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
|| i_read == 0 ) || i_read == 0 )
break; break;
*pi_data += i_read; *pi_data += i_read;
*pp_data = realloc( *pp_data, *pi_data + 1025 ); *pp_data = realloc_or_free( *pp_data, *pi_data + 1025 );
assert( *pp_data );
} }
while ( !p_object->b_die while ( !p_object->b_die
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include <vlc_aout.h> #include <vlc_aout.h>
#include <vlc_fourcc.h> #include <vlc_fourcc.h>
#include <vlc_memory.h>
#include "input_internal.h" #include "input_internal.h"
#include "clock.h" #include "clock.h"
#include "decoder.h" #include "decoder.h"
...@@ -2346,7 +2348,9 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args ) ...@@ -2346,7 +2348,9 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
if( p_fmt->i_extra ) if( p_fmt->i_extra )
{ {
es->fmt.i_extra = p_fmt->i_extra; es->fmt.i_extra = p_fmt->i_extra;
es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra ); es->fmt.p_extra = realloc_or_free( es->fmt.p_extra,
p_fmt->i_extra );
assert( es->fmt.p_extra );
memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra ); memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
if( !es->p_dec ) if( !es->p_dec )
...@@ -2358,7 +2362,8 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args ) ...@@ -2358,7 +2362,8 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
#else #else
es->p_dec->fmt_in.i_extra = p_fmt->i_extra; es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
es->p_dec->fmt_in.p_extra = es->p_dec->fmt_in.p_extra =
realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra ); realloc_or_free( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
assert( es->p_dec->fmt_in.p_extra );
memcpy( es->p_dec->fmt_in.p_extra, memcpy( es->p_dec->fmt_in.p_extra,
p_fmt->p_extra, p_fmt->i_extra ); p_fmt->p_extra, p_fmt->i_extra );
#endif #endif
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_memory.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
...@@ -2925,8 +2926,9 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta ...@@ -2925,8 +2926,9 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta
input_attachment_t **attachment = *ppp_attachment; input_attachment_t **attachment = *ppp_attachment;
int i; int i;
attachment = realloc( attachment, attachment = realloc_or_free( attachment,
sizeof(input_attachment_t**) * ( i_attachment + i_new ) ); sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
assert( attachment );
for( i = 0; i < i_new; i++ ) for( i = 0; i < i_new; i++ )
attachment[i_attachment++] = pp_new[i]; attachment[i_attachment++] = pp_new[i];
free( pp_new ); free( pp_new );
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <vlc_strings.h> #include <vlc_strings.h>
#include <vlc_osd.h> #include <vlc_osd.h>
#include <vlc_charset.h> #include <vlc_charset.h>
#include <vlc_memory.h>
#include <libvlc.h> #include <libvlc.h>
...@@ -805,7 +806,7 @@ static int AStreamPeekBlock( stream_t *s, const uint8_t **pp_peek, unsigned int ...@@ -805,7 +806,7 @@ static int AStreamPeekBlock( stream_t *s, const uint8_t **pp_peek, unsigned int
/* We need to create a local copy */ /* We need to create a local copy */
if( p_sys->i_peek < i_read ) if( p_sys->i_peek < i_read )
{ {
p_sys->p_peek = realloc( p_sys->p_peek, i_read ); p_sys->p_peek = realloc_or_free( p_sys->p_peek, i_read );
if( !p_sys->p_peek ) if( !p_sys->p_peek )
{ {
p_sys->i_peek = 0; p_sys->i_peek = 0;
...@@ -1112,7 +1113,7 @@ static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int ...@@ -1112,7 +1113,7 @@ static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int
if( p_sys->i_peek < i_read ) if( p_sys->i_peek < i_read )
{ {
p_sys->p_peek = realloc( p_sys->p_peek, i_read ); p_sys->p_peek = realloc_or_free( p_sys->p_peek, i_read );
if( !p_sys->p_peek ) if( !p_sys->p_peek )
{ {
p_sys->i_peek = 0; p_sys->i_peek = 0;
...@@ -1601,7 +1602,8 @@ char *stream_ReadLine( stream_t *s ) ...@@ -1601,7 +1602,8 @@ char *stream_ReadLine( stream_t *s )
if( psz_eol ) if( psz_eol )
{ {
i_data = (psz_eol - (char *)p_data) + 1; i_data = (psz_eol - (char *)p_data) + 1;
p_line = realloc( p_line, i_line + i_data + s->p_text->i_char_width ); /* add \0 */ p_line = realloc_or_free( p_line,
i_line + i_data + s->p_text->i_char_width ); /* add \0 */
if( !p_line ) if( !p_line )
goto error; goto error;
i_data = stream_Read( s, &p_line[i_line], i_data ); i_data = stream_Read( s, &p_line[i_line], i_data );
...@@ -1614,7 +1616,8 @@ char *stream_ReadLine( stream_t *s ) ...@@ -1614,7 +1616,8 @@ char *stream_ReadLine( stream_t *s )
} }
/* Read data (+1 for easy \0 append) */ /* Read data (+1 for easy \0 append) */
p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + s->p_text->i_char_width ); p_line = realloc_or_free( p_line,
i_line + STREAM_PROBE_LINE + s->p_text->i_char_width );
if( !p_line ) if( !p_line )
goto error; goto error;
i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE ); i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE );
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_memory.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> /* tolower() */ #include <ctype.h> /* tolower() */
...@@ -640,7 +641,9 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule ...@@ -640,7 +641,9 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
psz_line = strdup( ppsz_property[i] ); psz_line = strdup( ppsz_property[i] );
for( j = i+1; j < i_property; j++ ) for( j = i+1; j < i_property; j++ )
{ {
psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 ); psz_line = realloc_or_free( psz_line,
strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
assert( psz_line );
strcat( psz_line, " " ); strcat( psz_line, " " );
strcat( psz_line, ppsz_property[j] ); strcat( psz_line, ppsz_property[j] );
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_memory.h>
#include <stdarg.h> /* va_list for BSD */ #include <stdarg.h> /* va_list for BSD */
...@@ -381,7 +382,6 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -381,7 +382,6 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
} }
msg_item_t * p_item = malloc (sizeof (*p_item)); msg_item_t * p_item = malloc (sizeof (*p_item));
if (p_item == NULL) if (p_item == NULL)
return; /* Uho! */ return; /* Uho! */
...@@ -401,13 +401,15 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -401,13 +401,15 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
if( psz_header ) if( psz_header )
{ {
psz_old = strdup( psz_header ); psz_old = strdup( psz_header );
psz_header = (char*)realloc( psz_header, i_header_size ); psz_header = realloc_or_free( psz_header, i_header_size );
assert( psz_header );
snprintf( psz_header, i_header_size , "[%s] %s", snprintf( psz_header, i_header_size , "[%s] %s",
p_obj->psz_header, psz_old ); p_obj->psz_header, psz_old );
} }
else else
{ {
psz_header = (char *)malloc( i_header_size ); psz_header = malloc( i_header_size );
assert( psz_header );
snprintf( psz_header, i_header_size, "[%s]", snprintf( psz_header, i_header_size, "[%s]",
p_obj->psz_header ); p_obj->psz_header );
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_memory.h>
#include "../libvlc.h" #include "../libvlc.h"
#include <vlc_aout.h> #include <vlc_aout.h>
...@@ -1123,11 +1124,9 @@ static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo ) ...@@ -1123,11 +1124,9 @@ static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
static vlc_list_t * NewList( int i_count ) static vlc_list_t * NewList( int i_count )
{ {
vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) ); vlc_list_t * p_list = malloc( sizeof( vlc_list_t ) );
if( p_list == NULL ) if( p_list == NULL )
{
return NULL; return NULL;
}
p_list->i_count = i_count; p_list->i_count = i_count;
...@@ -1169,8 +1168,8 @@ static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object, ...@@ -1169,8 +1168,8 @@ static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
return; return;
} }
p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1) p_list->p_values = realloc_or_free( p_list->p_values,
* sizeof( vlc_value_t ) ); (p_list->i_count + 1) * sizeof( vlc_value_t ) );
if( p_list->p_values == NULL ) if( p_list->p_values == NULL )
{ {
p_list->i_count = 0; p_list->i_count = 0;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_charset.h> #include <vlc_charset.h>
#include <vlc_memory.h>
#include "variables.h" #include "variables.h"
#include "libvlc.h" #include "libvlc.h"
...@@ -217,8 +218,9 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) ...@@ -217,8 +218,9 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
if( (p_priv->i_vars & 15) == 15 ) if( (p_priv->i_vars & 15) == 15 )
{ {
p_priv->p_vars = realloc( p_priv->p_vars, p_priv->p_vars = realloc_or_free( p_priv->p_vars,
(p_priv->i_vars+17) * sizeof(variable_t) ); (p_priv->i_vars+17) * sizeof(variable_t) );
assert( p_priv->p_vars );
} }
memmove( p_priv->p_vars + i_new + 1, memmove( p_priv->p_vars + i_new + 1,
...@@ -389,8 +391,10 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) ...@@ -389,8 +391,10 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name )
if( (p_priv->i_vars & 15) == 0 ) if( (p_priv->i_vars & 15) == 0 )
{ {
p_priv->p_vars = realloc( p_priv->p_vars, variable_t *p_vars = realloc( p_priv->p_vars,
(p_priv->i_vars) * sizeof( variable_t ) ); (p_priv->i_vars) * sizeof( variable_t ) );
if( p_vars )
p_priv->p_vars = p_vars;
} }
p_priv->i_vars--; p_priv->i_vars--;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_memory.h>
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -128,7 +129,7 @@ static module_config_t *vlc_config_create (module_t *module, int type) ...@@ -128,7 +129,7 @@ static module_config_t *vlc_config_create (module_t *module, int type)
if ((confsize & 0xf) == 0) if ((confsize & 0xf) == 0)
{ {
tab = realloc (tab, (confsize + 17) * sizeof (*tab)); tab = realloc_or_free (tab, (confsize + 17) * sizeof (*tab));
if (tab == NULL) if (tab == NULL)
return NULL; return NULL;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_memory.h>
#include "libvlc.h" #include "libvlc.h"
#include <stdlib.h> /* free(), strtol() */ #include <stdlib.h> /* free(), strtol() */
...@@ -1077,7 +1078,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank, ...@@ -1077,7 +1078,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
/* Add entry to cache */ /* Add entry to cache */
module_cache_t **pp_cache = p_bank->pp_cache; module_cache_t **pp_cache = p_bank->pp_cache;
pp_cache = realloc( pp_cache, (p_bank->i_cache + 1) * sizeof(void *) ); pp_cache = realloc_or_free( pp_cache, (p_bank->i_cache + 1) * sizeof(void *) );
if( pp_cache == NULL ) if( pp_cache == NULL )
return -1; return -1;
pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) ); pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) );
......
...@@ -563,7 +563,8 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, ...@@ -563,7 +563,8 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
{ {
p[4] = '\0'; p[4] = '\0';
answer->i_body = strlen((char*)answer->p_body) + 1; answer->i_body = strlen((char*)answer->p_body) + 1;
answer->p_body = realloc( answer->p_body, answer->i_body ); uint8_t *p_body = realloc( answer->p_body, answer->i_body );
if( p_body ) answer->p_body = p_body;
} }
} }
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#endif #endif
#include <vlc_network.h> #include <vlc_network.h>
#include <vlc_memory.h>
#ifndef INADDR_ANY #ifndef INADDR_ANY
# define INADDR_ANY 0x00000000 # define INADDR_ANY 0x00000000
...@@ -522,7 +523,8 @@ char *__net_Gets( vlc_object_t *p_this, int fd, const v_socket_t *p_vs ) ...@@ -522,7 +523,8 @@ char *__net_Gets( vlc_object_t *p_this, int fd, const v_socket_t *p_vs )
if( i_line == i_max ) if( i_line == i_max )
{ {
i_max += 1024; i_max += 1024;
psz_line = realloc( psz_line, i_max ); psz_line = realloc_or_free( psz_line, i_max );
assert( psz_line );
ptr = psz_line + i_line; ptr = psz_line + i_line;
} }
......
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
#include <vlc_stream.h> #include <vlc_stream.h>
#include <limits.h> #include <limits.h>
#include <vlc_art_finder.h> #include <vlc_art_finder.h>
#include <vlc_memory.h>
#include "art.h" #include "art.h"
#include "fetcher.h" #include "fetcher.h"
#include "playlist_internal.h" #include "playlist_internal.h"
/***************************************************************************** /*****************************************************************************
* Structures/definitions * Structures/definitions
*****************************************************************************/ *****************************************************************************/
...@@ -293,7 +293,7 @@ static int DownloadArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item ) ...@@ -293,7 +293,7 @@ static int DownloadArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
if( i_data >= INT_MAX - i_read ) if( i_data >= INT_MAX - i_read )
break; break;
p_data = realloc( p_data, i_data + i_read ); p_data = realloc_or_free( p_data, i_data + i_read );
if( !p_data ) if( !p_data )
break; break;
......
...@@ -607,6 +607,7 @@ char *str_format_time( const char *tformat ) ...@@ -607,6 +607,7 @@ char *str_format_time( const char *tformat )
{ \ { \
int len = strlen( string ); \ int len = strlen( string ); \
dst = realloc( dst, i_size = i_size + len );\ dst = realloc( dst, i_size = i_size + len );\
assert( dst ); \
memcpy( (dst+d), string, len ); \ memcpy( (dst+d), string, len ); \
d += len; \ d += len; \
free( string ); \ free( string ); \
...@@ -622,6 +623,7 @@ char *str_format_time( const char *tformat ) ...@@ -622,6 +623,7 @@ char *str_format_time( const char *tformat )
{ \ { \
int len = strlen( string ); \ int len = strlen( string ); \
dst = realloc( dst, i_size = i_size + len );\ dst = realloc( dst, i_size = i_size + len );\
assert( dst ); \
memcpy( dst+d, string, len ); \ memcpy( dst+d, string, len ); \
d += len; \ d += len; \
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment