From 64f5accb3aaadc6af75234e8b4b3c0880341f341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 11 Apr 2007 09:23:33 +0000 Subject: [PATCH] * 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 --- src/add-ons/translators/raw/RAW.cpp | 11 ++++- src/add-ons/translators/raw/RAWTranslator.cpp | 41 +++++++++---------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/add-ons/translators/raw/RAW.cpp b/src/add-ons/translators/raw/RAW.cpp index 94d80cea21..a518c731a7 100644 --- a/src/add-ons/translators/raw/RAW.cpp +++ b/src/add-ons/translators/raw/RAW.cpp @@ -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; } diff --git a/src/add-ons/translators/raw/RAWTranslator.cpp b/src/add-ons/translators/raw/RAWTranslator.cpp index f745dd8bc9..a35e11214e 100644 --- a/src/add-ons/translators/raw/RAWTranslator.cpp +++ b/src/add-ons/translators/raw/RAWTranslator.cpp @@ -15,6 +15,23 @@ #include +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);