diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 75b0a168ed832908c2394e5a372d718caecff1da..462bc942cee892dfdde36684cbb7fa976f0c7e10 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -260,6 +260,8 @@ static av_cold int encode_init(AVCodecContext* avc_context)
 
     /* Set up the output AVFrame */
     avc_context->coded_frame = av_frame_alloc();
+    if (!avc_context->coded_frame)
+        return AVERROR(ENOMEM);
 
     return 0;
 }