From ce605e3982881f13c4711bd8bfa64c9156c191bf Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 5 Dec 2014 18:00:27 +0100 Subject: [PATCH] use RAII for resource management --- src/tiff_reader.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/tiff_reader.cpp b/src/tiff_reader.cpp index 4ff22bf53..8797b6f4a 100644 --- a/src/tiff_reader.cpp +++ b/src/tiff_reader.cpp @@ -485,7 +485,7 @@ void tiff_reader::read_tiled(unsigned x0,unsigned y0,image_data_rgba8& image) TIFF* tif = open(stream_); if (tif) { - uint32* buf = (uint32*)_TIFFmalloc(tile_width_*tile_height_*sizeof(uint32)); + std::unique_ptr buf(new uint32_t[tile_width_*tile_height_]); int width=image.width(); int height=image.height(); @@ -507,7 +507,7 @@ void tiff_reader::read_tiled(unsigned x0,unsigned y0,image_data_rgba8& image) for (int x=start_x;x::read_tiled(unsigned x0,unsigned y0,image_data_rgba8& image) } } } - _TIFFfree(buf); } } @@ -533,8 +532,7 @@ void tiff_reader::read_stripped(unsigned x0,unsigned y0,image_data_rgba8& ima TIFF* tif = open(stream_); if (tif) { - uint32* buf = (uint32*)_TIFFmalloc(width_*rows_per_strip_*sizeof(uint32)); - + std::unique_ptr buf(new uint32_t[width_*rows_per_strip_]); int width=image.width(); int height=image.height(); @@ -551,7 +549,7 @@ void tiff_reader::read_stripped(unsigned x0,unsigned y0,image_data_rgba8& ima ty0 = std::max(y0,y)-y; ty1 = std::min(height+y0,y+rows_per_strip_)-y; - if (!TIFFReadRGBAStrip(tif,y,buf)) + if (!TIFFReadRGBAStrip(tif,y,buf.get())) { MAPNIK_LOG_ERROR(tiff_reader) << "TIFFReadRGBAStrip failed"; break; @@ -566,7 +564,6 @@ void tiff_reader::read_stripped(unsigned x0,unsigned y0,image_data_rgba8& ima ++row; } } - _TIFFfree(buf); } }