Merge pull request #4920 from thirtythreeforty/memory-errors

Fix sundry memory problems found with Valgrind/LSan
This commit is contained in:
Ingo Weyrich
2018-11-08 23:35:10 +01:00
committed by GitHub
8 changed files with 17 additions and 38 deletions

View File

@@ -419,7 +419,7 @@ std::map<std::string, std::string> getAliases(const Glib::ustring& profile_dir)
buffer[read] = 0; buffer[read] = 0;
cJSON_Minify(buffer.get()); cJSON_Minify(buffer.get());
const std::unique_ptr<cJSON> root(cJSON_Parse(buffer.get())); const std::unique_ptr<cJSON, decltype(&cJSON_Delete)> root(cJSON_Parse(buffer.get()), cJSON_Delete);
if (!root || !root->child) { if (!root || !root->child) {
if (settings->verbose) { if (settings->verbose) {
std::cout << "Could not parse 'camera_model_aliases.json' file." << std::endl; std::cout << "Could not parse 'camera_model_aliases.json' file." << std::endl;

View File

@@ -809,11 +809,6 @@ unsigned int FramesData::getFrameCount () const
return dcrawFrameCount ? dcrawFrameCount : frames.size(); return dcrawFrameCount ? dcrawFrameCount : frames.size();
} }
FrameData *FramesData::getFrameData (unsigned int frame) const
{
return frames.empty() || frame >= frames.size() ? nullptr : frames.at(frame);
}
bool FramesData::getPixelShift () const bool FramesData::getPixelShift () const
{ {
// So far only Pentax and Sony provide multi-frame Pixel Shift files. // So far only Pentax and Sony provide multi-frame Pixel Shift files.
@@ -1118,9 +1113,7 @@ FramesData::FramesData (const Glib::ustring& fname, std::unique_ptr<RawMetaDataL
// creating FrameData // creating FrameData
for (auto currFrame : exifManager.frames) { for (auto currFrame : exifManager.frames) {
FrameData* fd = new FrameData(currFrame, currFrame->getRoot(), roots.at(0)); frames.push_back(std::unique_ptr<FrameData>(new FrameData(currFrame, currFrame->getRoot(), roots.at(0))));
frames.push_back(fd);
} }
for (auto currRoot : roots) { for (auto currRoot : roots) {
rtexif::Tag* t = currRoot->getTag(0x83BB); rtexif::Tag* t = currRoot->getTag(0x83BB);
@@ -1142,8 +1135,7 @@ FramesData::FramesData (const Glib::ustring& fname, std::unique_ptr<RawMetaDataL
exifManager.parseJPEG (); exifManager.parseJPEG ();
roots = exifManager.roots; roots = exifManager.roots;
for (auto currFrame : exifManager.frames) { for (auto currFrame : exifManager.frames) {
FrameData* fd = new FrameData(currFrame, currFrame->getRoot(), roots.at(0)); frames.push_back(std::unique_ptr<FrameData>(new FrameData(currFrame, currFrame->getRoot(), roots.at(0))));
frames.push_back(fd);
} }
rewind (exifManager.f); // Not sure this is necessary rewind (exifManager.f); // Not sure this is necessary
iptc = iptc_data_new_from_jpeg_file (exifManager.f); iptc = iptc_data_new_from_jpeg_file (exifManager.f);
@@ -1161,9 +1153,7 @@ FramesData::FramesData (const Glib::ustring& fname, std::unique_ptr<RawMetaDataL
// creating FrameData // creating FrameData
for (auto currFrame : exifManager.frames) { for (auto currFrame : exifManager.frames) {
FrameData* fd = new FrameData(currFrame, currFrame->getRoot(), roots.at(0)); frames.push_back(std::unique_ptr<FrameData>(new FrameData(currFrame, currFrame->getRoot(), roots.at(0))));
frames.push_back(fd);
} }
for (auto currRoot : roots) { for (auto currRoot : roots) {
rtexif::Tag* t = currRoot->getTag(0x83BB); rtexif::Tag* t = currRoot->getTag(0x83BB);

View File

@@ -20,6 +20,7 @@
#define __IMAGEDATA_H__ #define __IMAGEDATA_H__
#include <cstdio> #include <cstdio>
#include <memory>
#include "rawimage.h" #include "rawimage.h"
#include <string> #include <string>
#include <glibmm.h> #include <glibmm.h>
@@ -89,7 +90,7 @@ public:
class FramesData : public FramesMetaData { class FramesData : public FramesMetaData {
private: private:
// frame's root IFD, can be a file root IFD or a SUB-IFD // frame's root IFD, can be a file root IFD or a SUB-IFD
std::vector<FrameData*> frames; std::vector<std::unique_ptr<FrameData>> frames;
// root IFD in the file // root IFD in the file
std::vector<rtexif::TagDirectory*> roots; std::vector<rtexif::TagDirectory*> roots;
IptcData* iptc; IptcData* iptc;
@@ -102,7 +103,6 @@ public:
void setDCRawFrameCount (unsigned int frameCount); void setDCRawFrameCount (unsigned int frameCount);
unsigned int getRootCount () const; unsigned int getRootCount () const;
unsigned int getFrameCount () const; unsigned int getFrameCount () const;
FrameData *getFrameData (unsigned int frame) const;
bool getPixelShift () const; bool getPixelShift () const;
bool getHDR (unsigned int frame = 0) const; bool getHDR (unsigned int frame = 0) const;
std::string getImageType (unsigned int frame) const; std::string getImageType (unsigned int frame) const;

View File

@@ -110,7 +110,6 @@ public:
return 0; return 0;
} }
virtual FrameData* getImageData (unsigned int frameNum) = 0;
virtual ImageMatrices* getImageMatrices () = 0; virtual ImageMatrices* getImageMatrices () = 0;
virtual bool isRAW () const = 0; virtual bool isRAW () const = 0;
virtual DCPProfile* getDCP (const ColorManagementParams &cmp, DCPProfile::ApplyState &as) virtual DCPProfile* getDCP (const ColorManagementParams &cmp, DCPProfile::ApplyState &as)

View File

@@ -168,10 +168,6 @@ public:
return ri->get_rotateDegree(); return ri->get_rotateDegree();
} }
FrameData* getImageData (unsigned int frameNum)
{
return idata->getFrameData (frameNum);
}
ImageMatrices* getImageMatrices () ImageMatrices* getImageMatrices ()
{ {
return &imatrices; return &imatrices;

View File

@@ -33,7 +33,7 @@ extern const Settings *settings;
LFModifier::~LFModifier() LFModifier::~LFModifier()
{ {
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfModifierMutex); MyMutex::MyLock lock(lfModifierMutex);
data_->Destroy(); data_->Destroy();
} }
} }
@@ -113,14 +113,14 @@ void LFModifier::correctCA(double &x, double &y, int cx, int cy, int channel) co
void LFModifier::processVignetteLine(int width, int y, float *line) const void LFModifier::processVignetteLine(int width, int y, float *line) const
{ {
MyMutex::MyLock lock(*lfModifierMutex); MyMutex::MyLock lock(lfModifierMutex);
data_->ApplyColorModification(line, 0, y, width, 1, LF_CR_1(INTENSITY), 0); data_->ApplyColorModification(line, 0, y, width, 1, LF_CR_1(INTENSITY), 0);
} }
void LFModifier::processVignetteLine3Channels(int width, int y, float *line) const void LFModifier::processVignetteLine3Channels(int width, int y, float *line) const
{ {
MyMutex::MyLock lock(*lfModifierMutex); MyMutex::MyLock lock(lfModifierMutex);
data_->ApplyColorModification(line, 0, y, width, 1, LF_CR_3(RED, GREEN, BLUE), 0); data_->ApplyColorModification(line, 0, y, width, 1, LF_CR_3(RED, GREEN, BLUE), 0);
} }
@@ -160,7 +160,6 @@ LFModifier::LFModifier(lfModifier *m, bool swap_xy, int flags):
swap_xy_(swap_xy), swap_xy_(swap_xy),
flags_(flags) flags_(flags)
{ {
lfModifierMutex = new MyMutex;
} }
@@ -378,14 +377,13 @@ bool LFDatabase::LoadDirectory(const char *dirname)
LFDatabase::LFDatabase(): LFDatabase::LFDatabase():
data_(nullptr) data_(nullptr)
{ {
lfDBMutex = new MyMutex;
} }
LFDatabase::~LFDatabase() LFDatabase::~LFDatabase()
{ {
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfDBMutex); MyMutex::MyLock lock(lfDBMutex);
data_->Destroy(); data_->Destroy();
} }
} }
@@ -401,7 +399,7 @@ std::vector<LFCamera> LFDatabase::getCameras() const
{ {
std::vector<LFCamera> ret; std::vector<LFCamera> ret;
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfDBMutex); MyMutex::MyLock lock(lfDBMutex);
auto cams = data_->GetCameras(); auto cams = data_->GetCameras();
while (*cams) { while (*cams) {
ret.emplace_back(); ret.emplace_back();
@@ -417,7 +415,7 @@ std::vector<LFLens> LFDatabase::getLenses() const
{ {
std::vector<LFLens> ret; std::vector<LFLens> ret;
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfDBMutex); MyMutex::MyLock lock(lfDBMutex);
auto lenses = data_->GetLenses(); auto lenses = data_->GetLenses();
while (*lenses) { while (*lenses) {
ret.emplace_back(); ret.emplace_back();
@@ -433,7 +431,7 @@ LFCamera LFDatabase::findCamera(const Glib::ustring &make, const Glib::ustring &
{ {
LFCamera ret; LFCamera ret;
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfDBMutex); MyMutex::MyLock lock(lfDBMutex);
auto found = data_->FindCamerasExt(make.c_str(), model.c_str()); auto found = data_->FindCamerasExt(make.c_str(), model.c_str());
if (found) { if (found) {
ret.data_ = found[0]; ret.data_ = found[0];
@@ -448,7 +446,7 @@ LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name) c
{ {
LFLens ret; LFLens ret;
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfDBMutex); MyMutex::MyLock lock(lfDBMutex);
auto found = data_->FindLenses(camera.data_, nullptr, name.c_str()); auto found = data_->FindLenses(camera.data_, nullptr, name.c_str());
for (size_t pos = 0; !found && pos < name.size(); ) { for (size_t pos = 0; !found && pos < name.size(); ) {
// try to split the maker from the model of the lens -- we have to // try to split the maker from the model of the lens -- we have to
@@ -486,7 +484,7 @@ std::unique_ptr<LFModifier> LFDatabase::getModifier(const LFCamera &camera, cons
{ {
std::unique_ptr<LFModifier> ret; std::unique_ptr<LFModifier> ret;
if (data_) { if (data_) {
MyMutex::MyLock lock(*lfDBMutex); MyMutex::MyLock lock(lfDBMutex);
if (camera && lens) { if (camera && lens) {
lfModifier *mod = lfModifier::Create(lens.data_, camera.getCropFactor(), width, height); lfModifier *mod = lfModifier::Create(lens.data_, camera.getCropFactor(), width, height);
int flags = LF_MODIFY_DISTORTION | LF_MODIFY_SCALE | LF_MODIFY_TCA; int flags = LF_MODIFY_DISTORTION | LF_MODIFY_SCALE | LF_MODIFY_TCA;

View File

@@ -57,7 +57,7 @@ private:
lfModifier *data_; lfModifier *data_;
bool swap_xy_; bool swap_xy_;
int flags_; int flags_;
MyMutex *lfModifierMutex; mutable MyMutex lfModifierMutex;
}; };
class LFCamera final class LFCamera final
@@ -122,7 +122,7 @@ private:
LFDatabase(); LFDatabase();
bool LoadDirectory(const char *dirname); bool LoadDirectory(const char *dirname);
MyMutex *lfDBMutex; mutable MyMutex lfDBMutex;
static LFDatabase instance_; static LFDatabase instance_;
lfDatabase *data_; lfDatabase *data_;
}; };

View File

@@ -69,10 +69,6 @@ public:
void getFullSize (int& w, int& h, int tr = TR_NONE); void getFullSize (int& w, int& h, int tr = TR_NONE);
void getSize (const PreviewProps &pp, int& w, int& h); void getSize (const PreviewProps &pp, int& w, int& h);
FrameData* getImageData (unsigned int frameNum)
{
return idata->getFrameData (frameNum);
}
ImageIO* getImageIO () ImageIO* getImageIO ()
{ {
return img; return img;