Commit 502e723f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input: fix vlc_attachment_New() error handling

Also use size_t for the size.
parent b2c77d44
...@@ -161,48 +161,54 @@ struct input_attachment_t ...@@ -161,48 +161,54 @@ struct input_attachment_t
char *psz_mime; char *psz_mime;
char *psz_description; char *psz_description;
int i_data; size_t i_data;
void *p_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, static inline input_attachment_t *vlc_input_attachment_New( const char *psz_name,
const char *psz_mime, const char *psz_mime,
const char *psz_description, const char *psz_description,
const void *p_data, const void *p_data,
int i_data ) size_t i_data )
{ {
input_attachment_t *a = input_attachment_t *a = (input_attachment_t *)malloc( sizeof (*a) );
(input_attachment_t*)malloc( sizeof(input_attachment_t) ); if( unlikely(a == NULL) )
if( !a )
return NULL; return NULL;
a->psz_name = strdup( psz_name ? psz_name : "" ); a->psz_name = strdup( psz_name ? psz_name : "" );
a->psz_mime = strdup( psz_mime ? psz_mime : "" ); a->psz_mime = strdup( psz_mime ? psz_mime : "" );
a->psz_description = strdup( psz_description ? psz_description : "" ); a->psz_description = strdup( psz_description ? psz_description : "" );
a->i_data = i_data; a->i_data = i_data;
a->p_data = NULL;
if( i_data > 0 )
{
a->p_data = malloc( i_data ); a->p_data = malloc( i_data );
if( a->p_data && p_data ) if( i_data > 0 && likely(p_data != NULL) )
memcpy( a->p_data, p_data, i_data ); 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)) )
{
vlc_input_attachment_Delete( a );
a = NULL;
} }
return a; return a;
} }
static inline input_attachment_t *vlc_input_attachment_Duplicate( const input_attachment_t *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, return vlc_input_attachment_New( a->psz_name, a->psz_mime, a->psz_description,
a->p_data, a->i_data ); 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. * input defines/constants.
......
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