[vlc-devel] commit: Add some more assert()s for unchecked malloc(). (JP Dinger )
git version control
git at videolan.org
Sat Dec 5 22:35:17 CET 2009
vlc | branch: master | JP Dinger <jpd at videolan.org> | Sat Dec 5 22:22:20 2009 +0100| [59b025e33a3e5997ff333ddc3321574fe6044254] | committer: JP Dinger
Add some more assert()s for unchecked malloc().
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=59b025e33a3e5997ff333ddc3321574fe6044254
---
src/modules/cache.c | 7 +++++++
src/network/httpd.c | 16 ++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/src/modules/cache.c b/src/modules/cache.c
index 09968d7..3f16b25 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -31,6 +31,7 @@
#include <vlc_common.h>
#include "libvlc.h"
+#include <assert.h>
#include <stdlib.h> /* free(), strtol() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strdup() */
@@ -228,8 +229,11 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, bool b_delete )
}
if( i_cache )
+ {
pp_cache = p_bank->pp_loaded_cache =
malloc( i_cache * sizeof(void *) );
+ assert( pp_cache );
+ }
#define LOAD_IMMEDIATE(a) \
if( fread( (void *)&a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
@@ -259,6 +263,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, bool b_delete )
int i_submodules;
pp_cache[i] = malloc( sizeof(module_cache_t) );
+ assert( pp_cache[i] );
p_bank->i_loaded_cache++;
/* Load common info */
@@ -430,8 +435,10 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
{
p_module->p_config[i].ppf_action =
malloc( p_module->p_config[i].i_action * sizeof(void *) );
+ assert( p_module->p_config[i].ppf_action );
p_module->p_config[i].ppsz_action_text =
malloc( p_module->p_config[i].i_action * sizeof(char *) );
+ assert( p_module->p_config[i].ppsz_action_text );
for (int j = 0; j < p_module->p_config[i].i_action; j++)
{
diff --git a/src/network/httpd.c b/src/network/httpd.c
index c29250f..2ccac34 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -461,6 +461,7 @@ httpd_file_t *httpd_FileNew( httpd_host_t *host,
httpd_file_sys_t *p_sys )
{
httpd_file_t *file = malloc( sizeof( httpd_file_t ) );
+ assert( file );
if( ( file->url = httpd_UrlNewUnique( host, psz_url, psz_user,
psz_password, p_acl )
@@ -593,6 +594,7 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
answer->i_body = sizeof("HTTP/1.0 xxx \r\n")
+ strlen(psz_status) + i_headers - 1;
psz_new = (char *)malloc( answer->i_body + 1);
+ assert( psz_new );
sprintf( psz_new, "HTTP/1.0 %03d %s\r\n", i_status, psz_status );
memcpy( &psz_new[strlen(psz_new)], psz_headers, i_headers );
free( answer->p_body );
@@ -610,6 +612,7 @@ httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
httpd_handler_sys_t *p_sys )
{
httpd_handler_t *handler = malloc( sizeof( httpd_handler_t ) );
+ assert( handler );
if( ( handler->url = httpd_UrlNewUnique( host, psz_url, psz_user,
psz_password, p_acl )
@@ -681,6 +684,7 @@ httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst
const char *psz_url_src )
{
httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
+ assert( rdir );
if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL, NULL ) ) )
{
@@ -787,6 +791,7 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
answer->i_body = i_write;
answer->p_body = malloc( i_write );
+ assert( answer->p_body );
memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
answer->i_body_offset += i_write;
@@ -810,6 +815,7 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
{
answer->i_body = stream->i_header;
answer->p_body = malloc( stream->i_header );
+ assert( answer->p_body );
memcpy( answer->p_body, stream->p_header, stream->i_header );
}
answer->i_body_offset = stream->i_buffer_last_pos;
@@ -863,6 +869,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
const vlc_acl_t *p_acl )
{
httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
+ assert( stream );
if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
psz_password, p_acl )
@@ -884,6 +891,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
stream->p_header = NULL;
stream->i_buffer_size = 5000000; /* 5 Mo per stream */
stream->p_buffer = malloc( stream->i_buffer_size );
+ assert( stream->p_buffer );
/* We set to 1 to make life simpler
* (this way i_body_offset can never be 0) */
stream->i_buffer_pos = 1;
@@ -909,6 +917,7 @@ int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
if( i_data > 0 )
{
stream->p_header = malloc( i_data );
+ assert( stream->p_header );
memcpy( stream->p_header, p_data, i_data );
}
vlc_mutex_unlock( &stream->lock );
@@ -1239,6 +1248,7 @@ static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url
}
url = malloc( sizeof( httpd_url_t ) );
+ assert( url );
url->host = host;
vlc_mutex_init( &url->lock );
@@ -1407,6 +1417,7 @@ static void httpd_ClientInit( httpd_client_t *cl, mtime_t now )
cl->i_buffer_size = HTTPD_CL_BUFSIZE;
cl->i_buffer = 0;
cl->p_buffer = malloc( cl->i_buffer_size );
+ assert( cl->p_buffer );
cl->i_mode = HTTPD_CLIENT_FILE;
cl->b_read_waiting = false;
@@ -1555,6 +1566,7 @@ static void httpd_ClientRecv( httpd_client_t *cl )
cl->query.i_channel = cl->p_buffer[1];
cl->query.i_body = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
cl->query.p_body = malloc( cl->query.i_body );
+ assert( cl->query.p_body );
cl->i_buffer -= 4;
memcpy( cl->query.p_body, cl->p_buffer + 4, cl->i_buffer );
}
@@ -1836,6 +1848,7 @@ static void httpd_ClientRecv( httpd_client_t *cl )
* request and close the connection
* to mark and of body (probably only RTSP) */
cl->query.p_body = malloc( cl->query.i_body );
+ assert( cl->query.p_body );
cl->i_buffer = 0;
}
else
@@ -1924,6 +1937,7 @@ static void httpd_ClientSend( httpd_client_t *cl )
cl->i_buffer_size = i_size;
free( cl->p_buffer );
cl->p_buffer = malloc( i_size );
+ assert( cl->p_buffer );
}
p = (char *)cl->p_buffer;
@@ -2367,6 +2381,7 @@ static void* httpd_HostThread( void *data )
cl->i_buffer_size = 1000;
free( cl->p_buffer );
cl->p_buffer = malloc( cl->i_buffer_size );
+ assert( cl->p_buffer );
cl->i_state = HTTPD_CLIENT_RECEIVING;
}
else
@@ -2385,6 +2400,7 @@ static void* httpd_HostThread( void *data )
cl->i_buffer_size = 1000;
free( cl->p_buffer );
cl->p_buffer = malloc( cl->i_buffer_size );
+ assert( cl->p_buffer );
cl->i_state = HTTPD_CLIENT_RECEIVING;
cl->b_read_waiting = false;
}
More information about the vlc-devel
mailing list