diff --git a/libavformat/utils.c b/libavformat/utils.c
index b5b49c93c4abd74d79bc0c8a3ce5e13a83ef8588..e4e4a8b4456443e247b1178eb564a387dfae87ca 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2704,7 +2704,7 @@ void avformat_close_input(AVFormatContext **ps)
     AVFormatContext *s = *ps;
     AVIOContext *pb = s->pb;
 
-    if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) &&
+    if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
         (s->flags & AVFMT_FLAG_CUSTOM_IO))
         pb = NULL;