diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 63de8fe752f3805b4d5a017e4c674aacf8673312..015a20ad859c3ac8019258ecf99053eee9a2c941 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -469,7 +469,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
                 }
             }
             if (!s->is_pipe)
-                avio_close(f[i]);
+                avio_closep(&f[i]);
             if (ret[i] > 0)
                 pkt->size += ret[i];
         }