diff --git a/libavformat/tee.c b/libavformat/tee.c
index f41327bc7e1caf42a35762dff719a546eaa111e8..10787cad294c57080fe7046ff29d66eb2964e1df 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -100,7 +100,7 @@ static int open_slave(AVFormatContext *avf, char *slave, AVFormatContext **ravf)
         av_dict_set(&options, "f", NULL, 0);
     }
 
-    avformat_alloc_output_context2(&avf2, NULL, format, filename);
+    ret = avformat_alloc_output_context2(&avf2, NULL, format, filename);
     if (ret < 0)
         goto fail;
     av_free(format);