diff mbox series

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

Message ID 20200111042526.32351-2-andriy.gelman@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/libzmq: Check return of zmq_setsockopt
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andriy Gelman Jan. 11, 2020, 4:25 a.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
---
 libavformat/libzmq.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

Comments

Andriy Gelman Jan. 20, 2020, 3:20 p.m. UTC | #1
On Fri, 10. Jan 23:25, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> Signed-off-by: Andriy Gelman <andriy.gelman@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
Paul B Mahol Jan. 20, 2020, 8:24 p.m. UTC | #2
LGTM

On 1/11/20, Andriy Gelman <andriy.gelman@gmail.com> wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
>
> Signed-off-by: Andriy Gelman <andriy.gelman@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
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Jan. 21, 2020, 1:56 p.m. UTC | #3
On Mon, Jan 20, 2020 at 09:24:30PM +0100, Paul B Mahol wrote:
> LGTM

will apply

thx

[...]
diff mbox series

Patch

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)