1
mirror of https://code.videolan.org/videolan/vlc synced 2024-08-27 04:21:53 +02:00

input: fix vlc_attachment_New() error handling

Also use size_t for the size.
This commit is contained in:
Rémi Denis-Courmont 2015-08-15 13:18:55 +03:00
parent b2c77d4497
commit 502e723f49

View File

@ -161,48 +161,54 @@ struct input_attachment_t
char *psz_mime;
char *psz_description;
int i_data;
size_t i_data;
void *p_data;
};
static inline void vlc_input_attachment_Delete( input_attachment_t *a )
{
if( !a )
return;
free( a->p_data );
free( a->psz_description );
free( a->psz_mime );
free( a->psz_name );
free( a );
}
static inline input_attachment_t *vlc_input_attachment_New( const char *psz_name,
const char *psz_mime,
const char *psz_description,
const void *p_data,
int i_data )
size_t i_data )
{
input_attachment_t *a =
(input_attachment_t*)malloc( sizeof(input_attachment_t) );
if( !a )
input_attachment_t *a = (input_attachment_t *)malloc( sizeof (*a) );
if( unlikely(a == NULL) )
return NULL;
a->psz_name = strdup( psz_name ? psz_name : "" );
a->psz_mime = strdup( psz_mime ? psz_mime : "" );
a->psz_description = strdup( psz_description ? psz_description : "" );
a->i_data = i_data;
a->p_data = NULL;
if( i_data > 0 )
a->p_data = malloc( i_data );
if( i_data > 0 && likely(p_data != NULL) )
memcpy( a->p_data, p_data, i_data );
if( unlikely(a->psz_name == NULL || a->psz_mime == NULL
|| a->psz_description || (i_data > 0 && a->p_data == NULL)) )
{
a->p_data = malloc( i_data );
if( a->p_data && p_data )
memcpy( a->p_data, p_data, i_data );
vlc_input_attachment_Delete( a );
a = NULL;
}
return a;
}
static inline input_attachment_t *vlc_input_attachment_Duplicate( const input_attachment_t *a )
{
return vlc_input_attachment_New( a->psz_name, a->psz_mime, a->psz_description,
a->p_data, a->i_data );
}
static inline void vlc_input_attachment_Delete( input_attachment_t *a )
{
if( !a )
return;
free( a->psz_name );
free( a->psz_mime );
free( a->psz_description );
free( a->p_data );
free( a );
}
/*****************************************************************************
* input defines/constants.