From 1573140165e14d8710a5f8543f6ca9ffd20350d1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 20 Jun 2016 14:00:47 +0100 Subject: [PATCH] Fixed potential memory leaks --- src/osgPlugins/txp/trpage_rarchive.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/osgPlugins/txp/trpage_rarchive.cpp b/src/osgPlugins/txp/trpage_rarchive.cpp index 27f8c1a4b..5eecd8d31 100644 --- a/src/osgPlugins/txp/trpage_rarchive.cpp +++ b/src/osgPlugins/txp/trpage_rarchive.cpp @@ -147,26 +147,50 @@ bool trpgr_Archive::ReadSubArchive(int row, int col, trpgEndian cpuNess) // Look for a magic # and endianness int32 bmagic; if (fread(&bmagic,sizeof(int32),1,bfp) != 1) + { + //close the block archive + fclose(bfp); return false; + } + // The block archive will always be the same endianness as the master if ( (bmagic != GetMagicNumber()) && (trpg_byteswap_int(bmagic) != GetMagicNumber()) ) + { + //close the block archive + fclose(bfp); return false; + } int32 bheaderSize=0; if (fread(&bheaderSize,sizeof(int32),1,bfp) != 1) + { + //close the block archive + fclose(bfp); return false; + } + if (ness != cpuNess) bheaderSize = trpg_byteswap_int(bheaderSize); + int bheadLen = bheaderSize; if (bheadLen < 0) + { + //close the block archive + fclose(bfp); return false; + } // Read in the header whole trpgMemReadBuffer bbuf(ness); bbuf.SetLength(bheadLen); char *bdata = bbuf.GetDataPtr(); if ((ret = GetHeaderData(bdata,bheadLen,bfp)) != bheadLen) + { + //close the block archive + fclose(bfp); return false; + } + //keep track of where this came from in the master table. tileTable.SetCurrentBlock(row,col,true); texTable.SetCurrentBlock(row,col);