Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Memory leak in image class for empty dimensions #649

Merged
merged 3 commits into from
Jun 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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