diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 638330230222145d272cb555761f8f882816acc1..ef4fc36c6094c8aac2f5bea7e266cb1d74d84520 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -562,7 +562,7 @@ static int huf_uncompress(GetByteContext *gb,
 
 fail:
     for (i = 0; i < HUF_DECSIZE; i++) {
-        if (hdec[i].p)
+        if (hdec)
             av_freep(&hdec[i].p);
     }