diff --git a/libavformat/wtv.c b/libavformat/wtv.c
index a3f8c2738855ed4a1d8044b426cae40efe6cf6e7..ce0122dc1c9ae2ff25dd2079536dd85ad8b6d9fa 100644
--- a/libavformat/wtv.c
+++ b/libavformat/wtv.c
@@ -632,8 +632,10 @@ static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int code
         if (!wst)
             return NULL;
         st = avformat_new_stream(s, NULL);
-        if (!st)
+        if (!st) {
+            av_free(wst);
             return NULL;
+        }
         st->id = sid;
         st->priv_data = wst;
     }