1diff --git a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c
2index cc5449cd6..f69b00148 100644
3--- a/third_party/libtiff/tif_ojpeg.c
4+++ b/third_party/libtiff/tif_ojpeg.c
5@@ -1790,7 +1790,10 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif)
6                        TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET);
7                        p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64);
8                        if (p!=64)
9+                       {
10+                               _TIFFfree(ob);
11                                return(0);
12+                       }
13                        sp->qtable[m]=ob;
14                        sp->sof_tq[m]=m;
15                }
16@@ -1854,7 +1857,10 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif)
17                                rb[sizeof(uint32)+5+n]=o[n];
18                        p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q);
19                        if (p!=q)
20+                       {
21+                               _TIFFfree(rb);
22                                return(0);
23+                       }
24                        sp->dctable[m]=rb;
25                        sp->sos_tda[m]=(m<<4);
26                }
27@@ -1918,7 +1924,10 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif)
28                                rb[sizeof(uint32)+5+n]=o[n];
29                        p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q);
30                        if (p!=q)
31+                       {
32+                               _TIFFfree(rb);
33                                return(0);
34+                       }
35                        sp->actable[m]=rb;
36                        sp->sos_tda[m]=(sp->sos_tda[m]|m);
37                }
38