[FFmpeg-devel] [PATCH 2/2] avformat/libzmq: Replace fail statements with goto

Andriy Gelman andriy.gelman at gmail.com
Mon Jan 20 17:20:11 EET 2020


On Fri, 10. Jan 23:25, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman at gmail.com>
> 
> Signed-off-by: Andriy Gelman <andriy.gelman at gmail.com>
> ---
>  libavformat/libzmq.c | 24 +++++++++++-------------
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/libavformat/libzmq.c b/libavformat/libzmq.c
> index 2df55542c7e..8c8b294c921 100644
> --- a/libavformat/libzmq.c
> +++ b/libavformat/libzmq.c
> @@ -101,16 +101,13 @@ static int zmq_proto_open(URLContext *h, const char *uri, int flags)
>          s->socket = zmq_socket(s->context, ZMQ_PUB);
>          if (!s->socket) {
>              av_log(h, AV_LOG_ERROR, "Error occured during zmq_socket(): %s\n", ZMQ_STRERROR);
> -            zmq_ctx_term(s->context);
> -            return AVERROR_EXTERNAL;
> +            goto fail_term;
>          }
>  
>          ret = zmq_bind(s->socket, uri);
>          if (ret == -1) {
>              av_log(h, AV_LOG_ERROR, "Error occured during zmq_bind(): %s\n", ZMQ_STRERROR);
> -            zmq_close(s->socket);
> -            zmq_ctx_term(s->context);
> -            return AVERROR_EXTERNAL;
> +            goto fail_close;
>          }
>      }
>  
> @@ -119,27 +116,28 @@ static int zmq_proto_open(URLContext *h, const char *uri, int flags)
>          s->socket = zmq_socket(s->context, ZMQ_SUB);
>          if (!s->socket) {
>              av_log(h, AV_LOG_ERROR, "Error occured during zmq_socket(): %s\n", ZMQ_STRERROR);
> -            zmq_ctx_term(s->context);
> -            return AVERROR_EXTERNAL;
> +            goto fail_term;
>          }
>  
>          ret = zmq_setsockopt(s->socket, ZMQ_SUBSCRIBE, "", 0);
>          if (ret == -1) {
>              av_log(h, AV_LOG_ERROR, "Error occured during zmq_setsockopt(): %s\n", ZMQ_STRERROR);
> -            zmq_close(s->socket);
> -            zmq_ctx_term(s->context);
> -            return AVERROR_EXTERNAL;
> +            goto fail_close;
>          }
>  
>          ret = zmq_connect(s->socket, uri);
>          if (ret == -1) {
>              av_log(h, AV_LOG_ERROR, "Error occured during zmq_connect(): %s\n", ZMQ_STRERROR);
> -            zmq_close(s->socket);
> -            zmq_ctx_term(s->context);
> -            return AVERROR_EXTERNAL;
> +            goto fail_close;
>          }
>      }
>      return 0;
> +
> +fail_close:
> +    zmq_close(s->socket);
> +fail_term:
> +    zmq_ctx_term(s->context);
> +    return AVERROR_EXTERNAL;
>  }
>  
>  static int zmq_proto_write(URLContext *h, const unsigned char *buf, int size)
> -- 
> 2.24.0
> 

ping

-- 
Andriy


More information about the ffmpeg-devel mailing list