Commit 9314bb48 authored by François Cartegnie's avatar François Cartegnie 🤞

vlc_arrays: split array_append in checked and w/abort

parent 8c69c05f
......@@ -307,15 +307,22 @@ static inline void vlc_array_insert( vlc_array_t *ar, void *elem, int idx )
ar->pp_elems = pp;
}
static inline void vlc_array_append( vlc_array_t *ar, void *elem )
static inline int vlc_array_append( vlc_array_t *ar, void *elem )
{
void **pp = (void **)realloc( ar->pp_elems,
sizeof( void * ) * (ar->i_count + 1) );
if( unlikely(pp == NULL) )
abort();
return -1;
pp[ar->i_count++] = elem;
ar->pp_elems = pp;
return 0;
}
static inline void vlc_array_append_or_abort( vlc_array_t *ar, void *elem )
{
if( vlc_array_append( ar, elem ) != 0 )
abort();
}
static inline void vlc_array_remove( vlc_array_t *ar, size_t idx )
......
......@@ -75,7 +75,7 @@ struct fingerprinter_thread_t
module_t * p_module;
void ( *pf_enqueue ) ( struct fingerprinter_thread_t *f, fingerprint_request_t *r );
int ( *pf_enqueue ) ( struct fingerprinter_thread_t *f, fingerprint_request_t *r );
fingerprint_request_t * ( *pf_getresults ) ( struct fingerprinter_thread_t *f );
void ( *pf_apply ) ( fingerprint_request_t *, size_t i_resultid );
};
......
......@@ -239,10 +239,17 @@ int libvlc_event_attach(libvlc_event_manager_t *em, libvlc_event_type_t type,
listener->p_user_data = opaque;
listener->pf_callback = callback;
int i_ret;
vlc_mutex_lock(&em->lock);
vlc_array_append(&em->listeners, listener);
if(vlc_array_append(&em->listeners, listener) != 0)
{
i_ret = VLC_EGENERIC;
free(listener);
}
else
i_ret = VLC_SUCCESS;
vlc_mutex_unlock(&em->lock);
return 0;
return i_ret;
}
/**************************************************************************
......
......@@ -335,7 +335,7 @@ void libvlc_media_list_internal_add_media( libvlc_media_list_t * p_mlist,
notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items ),
EventWillHappen );
vlc_array_append( &p_mlist->items, p_md );
vlc_array_append_or_abort( &p_mlist->items, p_md );
notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items )-1,
EventDidHappen );
}
......
......@@ -1028,7 +1028,7 @@ static es_out_id_t *esOutAdd(es_out_t *p_out, const es_format_t *p_fmt)
p_pair->i_id = p_fmt->i_id;
p_pair->p_es = p_es;
msg_Info(p_demux, "Adding ES %d", p_fmt->i_id);
vlc_array_append(&p_sys->es, p_pair);
vlc_array_append_or_abort(&p_sys->es, p_pair);
if (b_select) {
if (fmt.i_cat == AUDIO_ES) {
......
......@@ -68,7 +68,7 @@ static void entry_item_append( services_discovery_t *p_sd,
p_entry_item->p_entry = p_entry;
p_entry_item->p_item = p_item;
input_item_Hold( p_item );
vlc_array_append( &p_sys->entry_item_list, p_entry_item );
vlc_array_append_or_abort( &p_sys->entry_item_list, p_entry_item );
services_discovery_AddItem( p_sd, p_item );
}
......
......@@ -880,7 +880,7 @@ static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t
return -1;
}
vlc_array_append( &p_sys->segments_t, segment );
vlc_array_append_or_abort( &p_sys->segments_t, segment );
if( p_sys->psz_keyfile )
{
......
......@@ -342,7 +342,7 @@ static dbus_bool_t add_timeout(DBusTimeout *to, void *data)
dbus_timeout_set_data(to, expiry, free);
vlc_mutex_lock(&sys->lock);
vlc_array_append(&sys->timeouts, to);
vlc_array_append_or_abort(&sys->timeouts, to);
vlc_mutex_unlock(&sys->lock);
return TRUE;
......@@ -447,7 +447,7 @@ static dbus_bool_t add_watch( DBusWatch *p_watch, void *p_data )
intf_sys_t *p_sys = (intf_sys_t*) p_intf->p_sys;
vlc_mutex_lock( &p_sys->lock );
vlc_array_append( &p_sys->watches, p_watch );
vlc_array_append_or_abort( &p_sys->watches, p_watch );
vlc_mutex_unlock( &p_sys->lock );
return TRUE;
......@@ -942,7 +942,7 @@ static int InputCallback( vlc_object_t *p_this, const char *psz_var,
p_info->signal = SIGNAL_STATE;
}
if( p_info->signal )
vlc_array_append( &p_sys->events, p_info );
vlc_array_append_or_abort( &p_sys->events, p_info );
else
free( p_info );
vlc_mutex_unlock( &p_intf->p_sys->lock );
......@@ -1003,7 +1003,7 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var,
// Append the event
*p_info = info;
vlc_mutex_lock( &p_intf->p_sys->lock );
vlc_array_append( &p_intf->p_sys->events, p_info );
vlc_array_append_or_abort( &p_intf->p_sys->events, p_info );
vlc_mutex_unlock( &p_intf->p_sys->lock );
wakeup_main_loop( p_intf );
......
......@@ -58,7 +58,11 @@ bool Chromaprint::enqueue( input_item_t *p_item )
if ( ! p_r ) return false;
mtime_t t = input_item_GetDuration( p_item );
if ( t ) p_r->i_duration = (unsigned int) ( t / 1000000 );
p_fingerprinter->pf_enqueue( p_fingerprinter, p_r );
if( p_fingerprinter->pf_enqueue( p_fingerprinter, p_r ) != 0 )
{
fingerprint_request_Delete( p_r );
return false;
}
return true;
}
......
......@@ -80,22 +80,25 @@ vlc_module_end ()
* Requests lifecycle
*****************************************************************************/
static void EnqueueRequest( fingerprinter_thread_t *f, fingerprint_request_t *r )
static int EnqueueRequest( fingerprinter_thread_t *f, fingerprint_request_t *r )
{
fingerprinter_sys_t *p_sys = f->p_sys;
vlc_mutex_lock( &p_sys->incoming.lock );
vlc_array_append( &p_sys->incoming.queue, r );
int i_ret = vlc_array_append( &p_sys->incoming.queue, r );
vlc_mutex_unlock( &p_sys->incoming.lock );
return i_ret;
}
static void QueueIncomingRequests( fingerprinter_sys_t *p_sys )
{
vlc_mutex_lock( &p_sys->incoming.lock );
size_t i = vlc_array_count( &p_sys->incoming.queue );
while( i )
vlc_array_append( &p_sys->processing.queue,
vlc_array_item_at_index( &p_sys->incoming.queue, --i ) );
for( size_t i = vlc_array_count( &p_sys->incoming.queue ); i > 0 ; i-- )
{
fingerprint_request_t *r = vlc_array_item_at_index( &p_sys->incoming.queue, i - 1 );
if( vlc_array_append( &p_sys->processing.queue, r ) )
fingerprint_request_Delete( r );
}
vlc_array_clear( &p_sys->incoming.queue );
vlc_mutex_unlock(&p_sys->incoming.lock);
}
......@@ -313,7 +316,8 @@ static void fill_metas_with_results( fingerprint_request_t *p_r, acoustid_finger
vlc_meta_Set( p_meta, vlc_meta_Title, p_record->psz_title );
vlc_meta_Set( p_meta, vlc_meta_Artist, p_record->psz_artist );
vlc_meta_AddExtra( p_meta, "musicbrainz-id", p_record->s_musicbrainz_id );
vlc_array_append( & p_r->results.metas_array, p_meta );
if( vlc_array_append( & p_r->results.metas_array, p_meta ) )
vlc_meta_Delete( p_meta );
}
}
}
......@@ -370,7 +374,8 @@ static void *Run( void *opaque )
/* copy results */
vlc_mutex_lock( &p_sys->results.lock );
vlc_array_append( &p_sys->results.queue, p_data );
if( vlc_array_append( &p_sys->results.queue, p_data ) )
fingerprint_request_Delete( p_data );
vlc_mutex_unlock( &p_sys->results.lock );
vlc_testcancel();
......
......@@ -620,9 +620,15 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
return VLC_EGENERIC;
}
if( vlc_array_append( &p_sys->tracks, tk ) )
{
free( tk->p_extra );
free( tk );
return VLC_EGENERIC;
}
es_format_Copy( &tk->fmt, p_input->p_fmt );
vlc_array_append( &p_sys->tracks, tk );
tk->i_id = vlc_array_index_of_item( &p_sys->tracks, tk ) + 1;
if( p_sys->b_asf_http )
......
......@@ -174,7 +174,7 @@ items_add_input( struct discovery_sys *p_sys, services_discovery_t *p_sd,
p_item->p_input_item = p_input_item;
p_item->p_renderer_item = NULL;
p_item->i_last_seen = mdate();
vlc_array_append( &p_sys->items, p_item );
vlc_array_append_or_abort( &p_sys->items, p_item );
services_discovery_AddItem( p_sd, p_input_item );
return VLC_SUCCESS;
......@@ -206,7 +206,7 @@ items_add_renderer( struct discovery_sys *p_sys, vlc_renderer_discovery_t *p_rd,
p_item->p_input_item = NULL;
p_item->p_renderer_item = p_renderer_item;
p_item->i_last_seen = mdate();
vlc_array_append( &p_sys->items, p_item );
vlc_array_append_or_abort( &p_sys->items, p_item );
vlc_rd_add_item( p_rd, p_renderer_item );
return VLC_SUCCESS;
......
......@@ -1565,7 +1565,7 @@ static int parse_Manifest( stream_t *s, manifest_t *m )
new_stream->bitrate = medias[i].bitrate;
vlc_array_append( &sys->hds_streams, new_stream );
vlc_array_append_or_abort( &sys->hds_streams, new_stream );
msg_Info( (vlc_object_t*)s, "New track with quality_segment(%s), bitrate(%u), timescale(%u), movie_id(%s), segment_run_count(%d), fragment_run_count(%u)",
new_stream->quality_segment_modifier?new_stream->quality_segment_modifier:"", new_stream->bitrate, new_stream->timescale,
......
......@@ -130,7 +130,11 @@ mrl_FragmentSplit( vlc_array_t* out_items,
if( unlikely( !decoded ) || !vlc_uri_decode( decoded ) )
goto error;
vlc_array_append( out_items, decoded );
if( vlc_array_append( out_items, decoded ) )
{
free( decoded );
goto error;
}
payload += len;
}
......
......@@ -188,13 +188,19 @@ dialog_add_locked(vlc_dialog_provider *p_provider, enum dialog_type i_type)
if (p_id == NULL)
return NULL;
if(vlc_array_append(&p_provider->dialog_array, p_id))
{
free(p_id);
return NULL;
}
vlc_mutex_init(&p_id->lock);
vlc_cond_init(&p_id->wait);
p_id->i_type = i_type;
p_id->i_refcount = 2; /* provider and callbacks */
vlc_array_append(&p_provider->dialog_array, p_id);
return p_id;
}
......
......@@ -218,8 +218,13 @@ int background_worker_Push( struct background_worker* worker, void* entity,
item->timeout = timeout < 0 ? worker->conf.default_timeout : timeout;
vlc_mutex_lock( &worker->lock );
vlc_array_append( &worker->tail.data, item );
int i_ret = vlc_array_append( &worker->tail.data, item );
vlc_cond_signal( &worker->tail.wait );
if( i_ret != 0 )
{
free( item );
return VLC_EGENERIC;
}
if( worker->head.active == false )
{
......
......@@ -340,11 +340,14 @@ bool vlc_http_cookies_store(vlc_http_cookie_jar_t *p_jar, const char *cookies,
break;
}
}
vlc_array_append( &p_jar->cookies, cookie );
bool b_ret = (vlc_array_append( &p_jar->cookies, cookie ) == 0);
if( !b_ret )
cookie_destroy( cookie );
vlc_mutex_unlock( &p_jar->lock );
return true;
return b_ret;
}
char *vlc_http_cookies_fetch(vlc_http_cookie_jar_t *p_jar, bool secure,
......
......@@ -852,8 +852,8 @@ sout_stream_t *sout_StreamChainNew(sout_instance_t *p_sout, const char *psz_chai
free( psz_parser );
psz_parser = psz_rest_chain;
vlc_array_append(&cfg, p_cfg);
vlc_array_append(&name, psz_name);
vlc_array_append_or_abort(&cfg, p_cfg);
vlc_array_append_or_abort(&name, psz_name);
}
size_t i = vlc_array_count(&name);
......@@ -870,7 +870,7 @@ sout_stream_t *sout_StreamChainNew(sout_instance_t *p_sout, const char *psz_chai
if(i == vlc_array_count(&name) - 1 && pp_last)
*pp_last = p_next; /* last module created in the chain */
vlc_array_append(&module, p_next);
vlc_array_append_or_abort(&module, p_next);
}
vlc_array_clear(&name);
......
......@@ -747,7 +747,7 @@ static void ThreadChangeFilters(vout_thread_t *vout,
if (likely(e))
{
free(config_ChainCreate(&e->name, &e->cfg, "deinterlace"));
vlc_array_append(&array_static, e);
vlc_array_append_or_abort(&array_static, e);
}
}
......@@ -764,9 +764,9 @@ static void ThreadChangeFilters(vout_thread_t *vout,
e->name = name;
e->cfg = cfg;
if (!strcmp(e->name, "postproc"))
vlc_array_append(&array_static, e);
vlc_array_append_or_abort(&array_static, e);
else
vlc_array_append(&array_interactive, e);
vlc_array_append_or_abort(&array_interactive, e);
}
else {
if (cfg)
......
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