[FFmpeg-devel] [PATCH 15/22] ffserver.c: Simplify error handling in server creation.

Stephan Holljes klaxa1337 at googlemail.com
Fri Jun 1 01:24:08 EEST 2018


Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>
---
 ffserver.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 6f76c3e..fd8cadd 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -534,13 +534,12 @@ void *run_server(void *arg) {
     pubs = av_mallocz_array(config->nb_streams, sizeof(struct PublisherContext*));
     if (!pubs) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate publishers\n");
-        return NULL;
+        goto error_cleanup;
     }
     ifmt_ctxs = av_mallocz_array(config->nb_streams, sizeof(AVFormatContext*));
     if (!ifmt_ctxs) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate input format contexts.\n");
-        av_free(pubs);
-        return NULL;
+        goto error_cleanup;
     }
     
     av_log_set_level(AV_LOG_INFO);
@@ -554,36 +553,22 @@ void *run_server(void *arg) {
     rinfos = av_mallocz_array(config->nb_streams, sizeof(struct ReadInfo));
     if (!rinfos) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate read infos.\n");
-        av_free(pubs);
-        av_free(ifmt_ctxs);
-        return NULL;
+        goto error_cleanup;
     }
     winfos_p = av_mallocz_array(config->nb_streams, sizeof(struct WriteInfo*));
     if (!winfos_p) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate write info pointers.\n");
-        av_free(pubs);
-        av_free(ifmt_ctxs);
-        av_free(rinfos);
-        return NULL;
+        goto error_cleanup;
     }
     r_threads = av_mallocz_array(config->nb_streams, sizeof(pthread_t));
     if (!r_threads) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate read thread handles.\n");
-        av_free(pubs);
-        av_free(ifmt_ctxs);
-        av_free(rinfos);
-        av_free(winfos_p);
-        return NULL;
+        goto error_cleanup;
     }
     w_threads_p = av_mallocz_array(config->nb_streams, sizeof(pthread_t*));
     if (!w_threads_p) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate write thread handle pointers.\n");
-        av_free(pubs);
-        av_free(ifmt_ctxs);
-        av_free(rinfos);
-        av_free(winfos_p);
-        av_free(r_threads);
-        return NULL;
+        goto error_cleanup;
     }
     
     for (stream_index = 0; stream_index < config->nb_streams; stream_index++) {
@@ -671,6 +656,15 @@ end:
     av_free(ifmt_ctxs);
 
     return NULL;
+
+error_cleanup:
+    av_free(rinfos);
+    av_free(winfos_p);
+    av_free(r_threads);
+    av_free(w_threads_p);
+    av_free(pubs);
+    av_free(ifmt_ctxs);
+    return NULL;
 }
 
 int main(int argc, char *argv[])
-- 
2.16.2



More information about the ffmpeg-devel mailing list