Skip to content

Commit

Permalink
free memory if precalculateTileInfo throws
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman authored and cary-ilm committed Aug 12, 2020
1 parent 7212e33 commit 425c104
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
46 changes: 29 additions & 17 deletions OpenEXR/IlmImf/ImfMultiPartInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,25 +451,37 @@ MultiPartInputFile::Data::createTileOffsets(const Header& header)
// Precompute level and tile information
//

int* numXTiles;
int* numYTiles;
int* numXTiles = nullptr;
int* numYTiles = nullptr;
int numXLevels, numYLevels;
TileDescription tileDesc = header.tileDescription();
precalculateTileInfo (tileDesc,
minX, maxX,
minY, maxY,
numXTiles, numYTiles,
numXLevels, numYLevels);

TileOffsets* tileOffsets = new TileOffsets (tileDesc.mode,
numXLevels,
numYLevels,
numXTiles,
numYTiles);
delete [] numXTiles;
delete [] numYTiles;

return tileOffsets;
try
{

precalculateTileInfo (tileDesc,
minX, maxX,
minY, maxY,
numXTiles, numYTiles,
numXLevels, numYLevels);

TileOffsets* tileOffsets = new TileOffsets (tileDesc.mode,
numXLevels,
numYLevels,
numXTiles,
numYTiles);
delete [] numXTiles;
delete [] numYTiles;

return tileOffsets;

}
catch(...)
{
delete [] numXTiles;
delete [] numYTiles;
throw;
}

}


Expand Down
26 changes: 13 additions & 13 deletions OpenEXR/IlmImf/ImfTiledMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,23 @@ getTiledChunkOffsetTableSize(const Header& header)
// Precompute level and tile information.
//

int* numXTiles;
int* numYTiles;
int* numXTiles=nullptr;
int* numYTiles=nullptr;
int numXLevels;
int numYLevels;
precalculateTileInfo (header.tileDescription(),
dataWindow.min.x, dataWindow.max.x,
dataWindow.min.y, dataWindow.max.y,
numXTiles, numYTiles,
numXLevels, numYLevels);

//
// Calculate lineOffsetSize.
//
Int64 lineOffsetSize = 0;
const TileDescription &desc = header.tileDescription();
try
{
precalculateTileInfo (header.tileDescription(),
dataWindow.min.x, dataWindow.max.x,
dataWindow.min.y, dataWindow.max.y,
numXTiles, numYTiles,
numXLevels, numYLevels);

//
// Calculate lineOffsetSize.
//
Int64 lineOffsetSize = 0;
const TileDescription &desc = header.tileDescription();
switch (desc.mode)
{
case ONE_LEVEL:
Expand Down

0 comments on commit 425c104

Please sign in to comment.