Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2cac3fcd authored by Jens Gulin's avatar Jens Gulin Committed by Johan Redestig
Browse files

Memory leak solved in MPEG4Extractor::parseChunk for cover art

Repeated leaks detected in mediaserver context. Most chunks small but
some bigger. Adding up it was not uncommon to see 200Mb footprint.
libc memdebug allocation call stack showed the root cause in "covr"
parsing - that explains why content often was empty but sometimes big.

Change-Id: I0de6c1eeef174d2529973ff9c6a020ec3dd44c75
parent f0e3acd0
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <string.h>

#include <media/stagefright/foundation/ABitReader.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/DataSource.h>
@@ -1426,18 +1427,15 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
            if (mFileMetaData != NULL) {
                ALOGV("chunk_data_size = %lld and data_offset = %lld",
                        chunk_data_size, data_offset);
                uint8_t *buffer = new uint8_t[chunk_data_size + 1];
                sp<ABuffer> buffer = new ABuffer(chunk_data_size + 1);
                if (mDataSource->readAt(
                    data_offset, buffer, chunk_data_size) != (ssize_t)chunk_data_size) {
                    delete[] buffer;
                    buffer = NULL;

                    data_offset, buffer->data(), chunk_data_size) != (ssize_t)chunk_data_size) {
                    return ERROR_IO;
                }
                const int kSkipBytesOfDataBox = 16;
                mFileMetaData->setData(
                    kKeyAlbumArt, MetaData::TYPE_NONE,
                    buffer + kSkipBytesOfDataBox, chunk_data_size - kSkipBytesOfDataBox);
                    buffer->data() + kSkipBytesOfDataBox, chunk_data_size - kSkipBytesOfDataBox);
            }

            *offset += chunk_size;