[vlc-devel] [PATCH 1/2] httpd: refactor error handling

Alexandre Janniaux ajanni at videolabs.io
Mon Nov 25 10:05:31 CET 2019


Hi,

Actually the patch is not 100% correct, I should have
removed the check on stream in the error: section.

Fixed locally.

Regards,
--
Alexandre Janniaux
Videolabs

On Sun, Nov 24, 2019 at 09:37:08PM +0100, Alexandre Janniaux wrote:
> Refactor error handling to remove xstrdup and xmalloc.
> ---
>  src/network/httpd.c | 30 ++++++++++++++++++++++++------
>  1 file changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/src/network/httpd.c b/src/network/httpd.c
> index e21cb853c3..7c27f371fe 100644
> --- a/src/network/httpd.c
> +++ b/src/network/httpd.c
> @@ -751,21 +751,29 @@ httpd_stream_t *httpd_StreamNew(httpd_host_t *host,
>      if (!stream)
>          return NULL;
>
> +    stream->psz_mime = NULL;
> +    stream->p_buffer = NULL;
> +
>      stream->url = httpd_UrlNew(host, psz_url, psz_user, psz_password);
> -    if (!stream->url) {
> -        free(stream);
> -        return NULL;
> -    }
> +    if (!stream->url)
> +        goto error;
>
>      vlc_mutex_init(&stream->lock);
>      if (psz_mime == NULL || psz_mime[0] == '\0')
>          psz_mime = vlc_mime_Ext2Mime(psz_url);
> -    stream->psz_mime = xstrdup(psz_mime);
> +
> +    stream->psz_mime = strdup(psz_mime);
> +    if (stream->psz_mime == NULL)
> +        goto error;
>
>      stream->i_header = 0;
>      stream->p_header = NULL;
>      stream->i_buffer_size = 5000000;    /* 5 Mo per stream */
> -    stream->p_buffer = xmalloc(stream->i_buffer_size);
> +
> +    stream->p_buffer = malloc(stream->i_buffer_size);
> +    if (stream->p_buffer == NULL)
> +        goto error;
> +
>      /* We set to 1 to make life simpler
>       * (this way i_body_offset can never be 0) */
>      stream->i_buffer_pos = 1;
> @@ -783,6 +791,16 @@ httpd_stream_t *httpd_StreamNew(httpd_host_t *host,
>                      (httpd_callback_sys_t*)stream);
>
>      return stream;
> +
> +error:
> +    free(stream->psz_mime);
> +
> +    if (stream && stream->url)
> +        httpd_UrlDelete(stream->url);
> +
> +    free(stream);
> +
> +    return NULL;
>  }
>
>  int httpd_StreamHeader(httpd_stream_t *stream, uint8_t *p_data, int i_data)
> --
> 2.24.0
>


More information about the vlc-devel mailing list