* Fixed a few large memory holes (Dano even crashes on low memory...).

* Removed printing progress updates to stdout.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20649 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-04-11 09:23:33 +00:00
parent 5b91a7be30
commit 64f5accb3a
2 changed files with 30 additions and 22 deletions

View File

@ -118,6 +118,7 @@ DCRaw::DCRaw(BPositionIO& stream)
fThumbIndex(-1),
fDNGVersion(0),
fIsTIFF(false),
fImageData(NULL),
fThreshold(0),
fHalfSize(false),
fUseCameraWhiteBalance(true),
@ -170,7 +171,9 @@ DCRaw::~DCRaw()
delete[] fCurve;
delete[] cbrt;
free(fHistogram);
free(fImageData);
}
@ -3328,8 +3331,11 @@ DCRaw::ReadImageAt(uint32 index, uint8*& outputBuffer, size_t& bufferSize)
}
outputBuffer = (uint8*)malloc(bufferSize);
if (outputBuffer == NULL)
if (outputBuffer == NULL) {
free(fImageData);
fImageData = NULL;
throw (status_t)B_NO_MEMORY;
}
fRead.Seek(image.data_offset, SEEK_SET);
@ -3372,6 +3378,9 @@ DCRaw::ReadImageAt(uint32 index, uint8*& outputBuffer, size_t& bufferSize)
_WriteJPEG(image, outputBuffer);
}
free(fImageData);
fImageData = NULL;
return B_OK;
}

View File

@ -15,6 +15,23 @@
#include <string.h>
class FreeAllocation {
public:
FreeAllocation(void* buffer)
:
fBuffer(buffer)
{
}
~FreeAllocation()
{
free(fBuffer);
}
private:
void* fBuffer;
};
// Extensions that ShowImage supports
const char* kDocumentCount = "/documentCount";
const char* kDocumentIndex = "/documentIndex";
@ -65,7 +82,6 @@ const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_for
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
// #pragma mark -
@ -140,9 +156,6 @@ RAWTranslator::DerivedIdentify(BPositionIO *stream,
}
bigtime_t gStart;
/*static*/ void
RAWTranslator::_ProgressMonitor(const char* message, float percentage,
void* data)
@ -154,19 +167,6 @@ RAWTranslator::_ProgressMonitor(const char* message, float percentage,
update.AddFloat("percent", percentage);
update.AddInt64("time", system_time());
#if 1
static bigtime_t last;
static int32 lastHash;
int32 hash = *(int32*)message;
if (system_time() - last > 500000 || hash != lastHash) {
printf("%6.3fs: %3.1f%% %s\n",
(system_time() - gStart) / 1000000.0, percentage, message);
last = system_time();
lastHash = hash;
}
#endif
messenger.SendMessage(&update);
}
@ -200,8 +200,6 @@ RAWTranslator::DerivedTranslate(BPositionIO* source,
size_t bufferSize;
status_t status;
gStart = system_time();
try {
status = raw.Identify();
@ -211,7 +209,7 @@ RAWTranslator::DerivedTranslate(BPositionIO* source,
imageIndex--;
else
imageIndex = 0;
if (imageIndex < 0 || imageIndex >= (int32)raw.CountImages())
status = B_BAD_VALUE;
}
@ -224,7 +222,8 @@ RAWTranslator::DerivedTranslate(BPositionIO* source,
if (status < B_OK)
return B_NO_TRANSLATOR;
printf("TOTAL: %6.3fs\n", (system_time() - gStart) / 1000000.0);
FreeAllocation _(buffer);
// frees the buffer on destruction
image_meta_info meta;
raw.GetMetaInfo(meta);