[vlc-devel] [PATCH] libvlc: media: remove flexible array member

Filip Roséen filip at videolabs.io
Mon May 23 19:22:18 CEST 2016


This code-path shouldn't be invoked too often, and as such the current
implementation is borderline premature optimization (in my opinion).

> diff --git a/lib/media.c b/lib/media.c
> index 0b20aaa..74c9c3b 100644
> --- a/lib/media.c
> +++ b/lib/media.c
> @@ -1189,6 +1189,7 @@ unsigned int libvlc_media_slaves_get( libvlc_media_t *p_md,
>              libvlc_media_slaves_release(pp_slaves, i);
>              return vlc_mutex_unlock( &p_input_item->lock ), 0;
>          }
> +        p_slave->psz_uri = (char *) ((uint8_t *)p_slave) + sizeof(*p_slave);
>          strcpy( p_slave->psz_uri, p_item_slave->psz_uri );

I would prefer a separate memory-allocation for the contents being pointed to by
`p_slave->psz_uri`, rather than allocating enough memory for the
`libvlc_media_slave_t` + the length of the uri-data (which is effectively
a simulation of flexible arrays, without using such).

Having `p_slave->psz_uri = strdup( p_item_slave->psz_uri )` aids readability,
and a separate `free( p_slave->psz_uri )` during slave clean-up shouldn't be too
intrusive.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20160523/4c600fa6/attachment.html>


More information about the vlc-devel mailing list