diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index 619a3561..b851a768 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -526,7 +526,7 @@ namespace Exiv2 { // Pimpl idiom class Impl; - Impl* p_; + std::auto_ptr p_; }; // class FileIo @@ -726,7 +726,7 @@ namespace Exiv2 { // Pimpl idiom class Impl; - Impl* p_; + std::auto_ptr p_; }; // class MemIo diff --git a/include/exiv2/properties.hpp b/include/exiv2/properties.hpp index 41576f0a..40eeb64a 100644 --- a/include/exiv2/properties.hpp +++ b/include/exiv2/properties.hpp @@ -312,7 +312,7 @@ namespace Exiv2 { private: // Pimpl idiom struct Impl; - Impl* p_; + std::auto_ptr p_; }; // class XmpKey diff --git a/include/exiv2/tags.hpp b/include/exiv2/tags.hpp index b9585046..4a3f33e4 100644 --- a/include/exiv2/tags.hpp +++ b/include/exiv2/tags.hpp @@ -222,7 +222,7 @@ namespace Exiv2 { private: // Pimpl idiom struct Impl; - Impl* p_; + std::auto_ptr p_; }; // class ExifKey diff --git a/include/exiv2/xmp_exiv2.hpp b/include/exiv2/xmp_exiv2.hpp index 6ccab6f5..b503bc7e 100644 --- a/include/exiv2/xmp_exiv2.hpp +++ b/include/exiv2/xmp_exiv2.hpp @@ -160,7 +160,7 @@ namespace Exiv2 { private: // Pimpl idiom struct Impl; - Impl* p_; + std::auto_ptr p_; }; // class Xmpdatum @@ -179,6 +179,9 @@ namespace Exiv2 { */ class EXIV2API XmpData { public: + //! Default constructor + XmpData() : xmpMetadata_(), xmpPacket_(), usePacket_(0) {} + //! XmpMetadata iterator type typedef XmpMetadata::iterator iterator; //! XmpMetadata const iterator type diff --git a/src/basicio.cpp b/src/basicio.cpp index 985f6d10..e887d444 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -371,7 +371,6 @@ namespace Exiv2 { FileIo::~FileIo() { close(); - delete p_; } int FileIo::munmap() @@ -1092,9 +1091,9 @@ namespace Exiv2 { void MemIo::Impl::reserve(long wcount) { - long need = wcount + idx_; + const long need = wcount + idx_; long blockSize = 32*1024; // 32768 ` - long maxBlockSize = 4*1024*1024; + const long maxBlockSize = 4*1024*1024; if (!isMalloced_) { // Minimum size for 1st block @@ -1103,7 +1102,9 @@ namespace Exiv2 { if ( data == NULL ) { throw Error(kerMallocFailed); } - std::memcpy(data, data_, size_); + if (data_ != NULL) { + std::memcpy(data, data_, size_); + } data_ = data; sizeAlloced_ = size; isMalloced_ = true; @@ -1141,14 +1142,15 @@ namespace Exiv2 { if (p_->isMalloced_) { std::free(p_->data_); } - delete p_; } long MemIo::write(const byte* data, long wcount) { p_->reserve(wcount); assert(p_->isMalloced_); - std::memcpy(&p_->data_[p_->idx_], data, wcount); + if (data != NULL) { + std::memcpy(&p_->data_[p_->idx_], data, wcount); + } p_->idx_ += wcount; return wcount; } diff --git a/src/properties.cpp b/src/properties.cpp index a933f64c..898fb7f8 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -2740,7 +2740,6 @@ namespace Exiv2 { XmpKey::~XmpKey() { - delete p_; } XmpKey::XmpKey(const XmpKey& rhs) : Key(rhs), p_(new Impl(*rhs.p_)) diff --git a/src/tags.cpp b/src/tags.cpp index ab22e577..9e74c990 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -3168,10 +3168,7 @@ namespace Exiv2 { { } - ExifKey::~ExifKey() - { - delete p_; - } + ExifKey::~ExifKey() {} ExifKey& ExifKey::operator=(const ExifKey& rhs) { diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index f95dfbe9..1db9ac71 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -380,7 +380,9 @@ namespace Exiv2 { if (newSize > size_) { setData(DataBuf(newSize)); } - memset(pData_, 0x0, size_); + if (pData_ != NULL) { + memset(pData_, 0x0, size_); + } size_ = value->copy(pData_, byteOrder); assert(size_ == newSize); setValue(value); diff --git a/src/xmp.cpp b/src/xmp.cpp index f149d3f7..e9c72145 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -175,7 +175,6 @@ namespace Exiv2 { Xmpdatum::~Xmpdatum() { - delete p_; } std::string Xmpdatum::key() const