[FFmpeg-devel] [PATCH 11/22] ffserver.c/segment.c: set *seg_p to NULL in case of allocation failure and check it

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


Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>
---
 ffserver.c | 4 ++++
 segment.c  | 1 +
 2 files changed, 5 insertions(+)

diff --git a/ffserver.c b/ffserver.c
index 3abf5f8..50d61e5 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -151,6 +151,10 @@ void *read_thread(void *arg)
                 av_log(NULL, AV_LOG_DEBUG, "Published new segment.\n");
             }
             segment_init(&seg, ifmt_ctx);
+            if (!seg) {
+                av_log(NULL, AV_LOG_ERROR, "Segment initialization failed, shutting down.\n");
+                goto end;
+            }
             seg->id = id++;
             av_log(NULL, AV_LOG_DEBUG, "Starting new segment, id: %d\n", seg->id);
         }
diff --git a/segment.c b/segment.c
index 986aeb5..72c4663 100644
--- a/segment.c
+++ b/segment.c
@@ -116,6 +116,7 @@ void segment_init(struct Segment **seg_p, AVFormatContext *fmt)
     struct Segment *seg = (struct Segment*) av_malloc(sizeof(struct Segment));
     if (!seg) {
         av_log(fmt, AV_LOG_ERROR, "Could not allocate segment.\n");
+        *seg_p = NULL;
         return;
     }
 
-- 
2.16.2



More information about the ffmpeg-devel mailing list