Segfault switching between JPEG images in SETM, Issue 2636

This commit is contained in:
Ingo
2015-01-13 00:42:25 +01:00
parent 4c39410dff
commit ba2a57f24d
2 changed files with 13 additions and 15 deletions

View File

@@ -142,8 +142,8 @@ void ImageIO::setOutputProfile (char* pdata, int plen) {
ImageIO::~ImageIO () { ImageIO::~ImageIO () {
if (embProfile) if (embProfile)
cmsCloseProfile(embProfile); cmsCloseProfile(embProfile);
delete [] loadedProfileData; deleteLoadedProfileData();
delete exifRoot; delete exifRoot;
delete [] profileData; delete [] profileData;
} }
@@ -339,7 +339,7 @@ int ImageIO::loadPNG (Glib::ustring fname) {
} }
int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize) int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
{ {
jpeg_decompress_struct cinfo; jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr; jpeg_error_mgr jerr;
cinfo.err = my_jpeg_std_error(&jerr); cinfo.err = my_jpeg_std_error(&jerr);
@@ -359,10 +359,8 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
//jpeg_memory_src (&cinfo,buffer,bufsize); //jpeg_memory_src (&cinfo,buffer,bufsize);
jpeg_read_header(&cinfo, TRUE); jpeg_read_header(&cinfo, TRUE);
if( loadedProfileData ){ deleteLoadedProfileData();
delete [] loadedProfileData; loadedProfileDataJpg = true;
loadedProfileData = NULL;
}
bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength); bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength);
if (hasprofile) if (hasprofile)
embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength); embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength);
@@ -406,7 +404,6 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
} }
int ImageIO::loadJPEG (Glib::ustring fname) { int ImageIO::loadJPEG (Glib::ustring fname) {
FILE *file=safe_g_fopen(fname,"rb"); FILE *file=safe_g_fopen(fname,"rb");
if (!file) if (!file)
return IMIO_CANNOTREADFILE; return IMIO_CANNOTREADFILE;
@@ -435,8 +432,8 @@ int ImageIO::loadJPEG (Glib::ustring fname) {
return IMIO_READERROR; return IMIO_READERROR;
} }
delete loadedProfileData; deleteLoadedProfileData();
loadedProfileData = NULL; loadedProfileDataJpg = true;
bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength); bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength);
if (hasprofile) if (hasprofile)
embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength); embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength);
@@ -651,10 +648,8 @@ int ImageIO::loadTIFF (Glib::ustring fname) {
char* profdata; char* profdata;
if( loadedProfileData ){ deleteLoadedProfileData();
delete [] loadedProfileData; loadedProfileDataJpg = false;
loadedProfileData = NULL;
}
if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &loadedProfileLength, &profdata)) { if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &loadedProfileLength, &profdata)) {
embProfile = cmsOpenProfileFromMem (profdata, loadedProfileLength); embProfile = cmsOpenProfileFromMem (profdata, loadedProfileLength);

View File

@@ -75,6 +75,7 @@ class ImageIO : virtual public ImageDatas {
char* profileData; char* profileData;
int profileLength; int profileLength;
char* loadedProfileData; char* loadedProfileData;
bool loadedProfileDataJpg;
int loadedProfileLength; int loadedProfileLength;
procparams::ExifPairs exifChange; procparams::ExifPairs exifChange;
IptcData* iptc; IptcData* iptc;
@@ -83,10 +84,12 @@ class ImageIO : virtual public ImageDatas {
IIOSampleFormat sampleFormat; IIOSampleFormat sampleFormat;
IIOSampleArrangement sampleArrangement; IIOSampleArrangement sampleArrangement;
private:
void deleteLoadedProfileData( ) { if(loadedProfileData) {if(loadedProfileDataJpg) free(loadedProfileData); else delete[] loadedProfileData;} loadedProfileData = NULL; }
public: public:
static Glib::ustring errorMsg[6]; static Glib::ustring errorMsg[6];
ImageIO () : pl (NULL), embProfile(NULL), profileData(NULL), profileLength(0), loadedProfileData(NULL), ImageIO () : pl (NULL), embProfile(NULL), profileData(NULL), profileLength(0), loadedProfileData(NULL),loadedProfileDataJpg(false),
loadedProfileLength(0), iptc(NULL), exifRoot (NULL), sampleFormat(IIOSF_UNKNOWN), loadedProfileLength(0), iptc(NULL), exifRoot (NULL), sampleFormat(IIOSF_UNKNOWN),
sampleArrangement(IIOSA_UNKNOWN) {} sampleArrangement(IIOSA_UNKNOWN) {}