Skip to content

Commit

Permalink
fix: Memory leak in image class for empty dimensions (boostorg#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-langer authored Jun 27, 2022
1 parent 5c3cfc7 commit 8d7034c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/boost/gil/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );

Expand Down

0 comments on commit 8d7034c

Please sign in to comment.