Skip to content

Commit

Permalink
refactor!: remove free() function from DataBuf to avoid potential pro…
Browse files Browse the repository at this point in the history
…blems, see #1542
  • Loading branch information
hassec committed May 27, 2021
1 parent 2c57f21 commit 758dd6b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
10 changes: 2 additions & 8 deletions include/exiv2/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ namespace Exiv2 {
be as a stack variable in functions that need a temporary data
buffer.
*/
class EXIV2API DataBuf {
public:
struct EXIV2API DataBuf {
//! @name Creators
//@{
//! Default constructor
Expand Down Expand Up @@ -237,13 +236,8 @@ namespace Exiv2 {
*/
EXV_WARN_UNUSED_RESULT std::pair<byte*, long> release();

/*!
@brief Free the internal buffer and reset the size to 0.
*/
void free();

//! Reset value
void reset(std::pair<byte*, long> =std::make_pair((byte*)(0),long(0)));
void reset(std::pair<byte*, long> = std::make_pair(nullptr, long(0)));
//@}

/*!
Expand Down
2 changes: 1 addition & 1 deletion src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ namespace Exiv2 {

void Image::clearIccProfile()
{
iccProfile_.free();
iccProfile_.reset();
}

void Image::setByteOrder(ByteOrder byteOrder)
Expand Down
8 changes: 4 additions & 4 deletions src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ namespace Exiv2 {
zlibResult = uncompress(result.pData_,&uncompressedLen,bytes,length);
// if result buffer is large than necessary, redo to fit perfectly.
if (zlibResult == Z_OK && static_cast<long>(uncompressedLen) < result.size_) {
result.free();
result.reset();

result.alloc(uncompressedLen);
zlibResult = uncompress(result.pData_,&uncompressedLen,bytes,length);
}
if (zlibResult == Z_BUF_ERROR) {
// the uncompressed buffer needs to be larger
result.free();
result.reset();

// Sanity - never bigger than 16mb
if (uncompressedLen > 16*1024*1024) zlibResult = Z_DATA_ERROR;
Expand All @@ -134,10 +134,10 @@ namespace Exiv2 {
zlibResult = compress(result.pData_,&compressedLen,bytes,length);
if (zlibResult == Z_BUF_ERROR) {
// the compressedArray needs to be larger
result.free();
result.reset();
compressedLen *= 2;
} else {
result.free();
result.reset();
result.alloc(compressedLen);
zlibResult = compress(result.pData_,&compressedLen,bytes,length);
}
Expand Down
7 changes: 0 additions & 7 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ namespace Exiv2 {
return p;
}

void DataBuf::free()
{
delete[] pData_;
pData_ = nullptr;
size_ = 0;
}

void DataBuf::reset(std::pair<byte*, long> p)
{
if (pData_ != p.first) {
Expand Down

0 comments on commit 758dd6b

Please sign in to comment.