diff --git a/libavformat/utils.c b/libavformat/utils.c
index aa8a117c2333590997e51ccfd2b6ab070f8e8651..f9d50ce78609ca77fff984179fbdffef78acc306 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2245,8 +2245,8 @@ int ff_new_chapter(AVFormatContext *s, int id, int64_t start, int64_t end, const
 
     if(!chapter){
         chapter= av_mallocz(sizeof(AVChapter));
-    if(!chapter)
-        return AVERROR(ENOMEM);
+        if(!chapter)
+            return AVERROR(ENOMEM);
         dynarray_add(&s->chapters, &s->num_chapters, chapter);
     }
     if(chapter->title)