From 8d7034c71cdb3ea1e946f57ca3b30e81b8a8b854 Mon Sep 17 00:00:00 2001 From: Marco Langer Date: Mon, 27 Jun 2022 22:59:52 +0200 Subject: [PATCH] fix: Memory leak in image class for empty dimensions (#649) --- include/boost/gil/image.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/boost/gil/image.hpp b/include/boost/gil/image.hpp index d6a321bd1..e3f943a83 100644 --- a/include/boost/gil/image.hpp +++ b/include/boost/gil/image.hpp @@ -449,6 +449,11 @@ class image { // if it throws and _memory!=0 the client must deallocate _memory _allocated_bytes = total_allocated_size_in_bytes(dimensions); + if (_allocated_bytes == 0) + { + return; + } + _memory=_alloc.allocate( _allocated_bytes ); unsigned char* tmp=(_align_in_bytes>0) ? (unsigned char*)align((std::size_t)_memory,_align_in_bytes) : _memory; @@ -465,6 +470,10 @@ class image std::size_t plane_size=row_size*dimensions.y; _allocated_bytes = total_allocated_size_in_bytes( dimensions ); + if (_allocated_bytes == 0) + { + return; + } _memory = _alloc.allocate( _allocated_bytes );