Replace a dubious manual return-value-optimization by a standard named-return-value-optimization to simplify leak detection.

This commit is contained in:
Adam Reichold
2015-11-28 14:30:38 +01:00
parent 1ed09dc049
commit e52ce5c485
3 changed files with 23 additions and 21 deletions

View File

@@ -2783,17 +2783,11 @@ TagDirectory* ExifManager::parseTIFF (FILE* f, bool skipIgnored)
return parse (f, 0, skipIgnored);
}
std::vector<Tag*> ExifManager::defTags;
// forthis: the byte order will be taken from directory "forthis"
const std::vector<Tag*>& ExifManager::getDefaultTIFFTags (TagDirectory* forthis)
std::vector<Tag*> ExifManager::getDefaultTIFFTags (TagDirectory* forthis)
{
std::vector<Tag*> defTags;
for (size_t i = 0; i < defTags.size(); i++) {
delete defTags[i];
}
defTags.clear ();
defTags.reserve (12);
defTags.push_back (new Tag (forthis, lookupAttrib(ifdAttribs, "ImageWidth"), 0, LONG));
defTags.push_back (new Tag (forthis, lookupAttrib(ifdAttribs, "ImageHeight"), 0, LONG));
defTags.push_back (new Tag (forthis, lookupAttrib(ifdAttribs, "XResolution"), 300, RATIONAL));
@@ -2843,14 +2837,16 @@ int ExifManager::createJPEGMarker (const TagDirectory* root, const rtengine::pro
cl->applyChange (i->first, i->second);
}
getDefaultTIFFTags (cl);
const std::vector<Tag*> defTags = getDefaultTIFFTags (cl);
defTags[0]->setInt (W, 0, LONG);
defTags[1]->setInt (H, 0, LONG);
defTags[8]->setInt (8, 0, SHORT);
for (int i = defTags.size() - 1; i >= 0; i--) {
cl->replaceTag (defTags[i]->clone (cl));
Tag* defTag = defTags[i];
cl->replaceTag (defTag->clone (cl));
delete defTag;
}
cl->sort ();
@@ -2928,7 +2924,7 @@ int ExifManager::createTIFFHeader (const TagDirectory* root, const rtengine::pro
}
// append default properties
getDefaultTIFFTags (cl);
const std::vector<Tag*> defTags = getDefaultTIFFTags (cl);
defTags[0]->setInt (W, 0, LONG);
defTags[1]->setInt (H, 0, LONG);
@@ -2939,7 +2935,9 @@ int ExifManager::createTIFFHeader (const TagDirectory* root, const rtengine::pro
}
for (int i = defTags.size() - 1; i >= 0; i--) {
cl->replaceTag (defTags[i]->clone (cl));
Tag* defTag = defTags[i];
cl->replaceTag (defTag->clone (cl));
delete defTag;
}
// calculate strip offsets

View File

@@ -306,8 +306,6 @@ public:
class ExifManager
{
static std::vector<Tag*> defTags;
static Tag* saveCIFFMNTag (FILE* f, TagDirectory* root, int len, const char* name);
public:
static TagDirectory* parse (FILE*f, int base, bool skipIgnored = true);
@@ -316,7 +314,10 @@ public:
static TagDirectory* parseCIFF (FILE* f, int base, int length);
static void parseCIFF (FILE* f, int base, int length, TagDirectory* root);
static const std::vector<Tag*>& getDefaultTIFFTags (TagDirectory* forthis);
/// @brief Get default tag for TIFF
/// @param forthis The byte order will be taken from the given directory.
/// @return The ownership of the return tags is passed to the caller.
static std::vector<Tag*> getDefaultTIFFTags (TagDirectory* forthis);
static int createJPEGMarker (const TagDirectory* root, const rtengine::procparams::ExifPairs& changeList, int W, int H, unsigned char* buffer);
static int createTIFFHeader (const TagDirectory* root, const rtengine::procparams::ExifPairs& changeList, int W, int H, int bps, const char* profiledata, int profilelen, const char* iptcdata, int iptclen, unsigned char* buffer);
};

View File

@@ -156,14 +156,17 @@ void ExifPanel::setImageData (const ImageMetaData* id)
idata = id;
exifTreeModel->clear ();
const std::vector<Tag*>& defTags = ExifManager::getDefaultTIFFTags (NULL);
const std::vector<Tag*> defTags = ExifManager::getDefaultTIFFTags (NULL);
for (size_t i = 0; i < defTags.size(); i++)
if (defTags[i]->nameToString() == "ImageWidth" || defTags[i]->nameToString() == "ImageHeight" || defTags[i]->nameToString() == "BitsPerSample") {
addTag (exifTreeModel->children(), defTags[i]->nameToString(), "?", AC_SYSTEM, false);
for (size_t i = 0; i < defTags.size(); i++) {
Tag* defTag = defTags[i];
if (defTag->nameToString() == "ImageWidth" || defTag->nameToString() == "ImageHeight" || defTag->nameToString() == "BitsPerSample") {
addTag (exifTreeModel->children(), defTag->nameToString(), "?", AC_SYSTEM, false);
} else {
addTag (exifTreeModel->children(), defTags[i]->nameToString(), defTags[i]->valueToString(), AC_SYSTEM, false);
addTag (exifTreeModel->children(), defTag->nameToString(), defTag->valueToString(), AC_SYSTEM, false);
}
delete defTag;
}
if (id && id->getExifData ()) {
// id->getExifData ()->printAll ();