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

Remove free() function from DataBuf #1687

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
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
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