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

Commit 034de6b1 authored by Romain Guy's avatar Romain Guy
Browse files

Plug memory leak that happens when reusing display lists

Bug #7195815

We did not reclaim resources when reusing an existing DisplayList to
record a new empty list of commands. This would lead to various memory
leaks: bitmaps, paints, paths, matrices, etc.

This is not a common case but some apps run into this situation,
such as Launcher.

Change-Id: I2eb14ac86a212123f8edbe42b70a7c1c51fa4145
parent 6ed9e438
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -143,6 +143,7 @@ void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) {


void DisplayList::clearResources() {
void DisplayList::clearResources() {
    sk_free((void*) mReader.base());
    sk_free((void*) mReader.base());
    mReader.setMemory(NULL, 0);


    delete mTransformMatrix;
    delete mTransformMatrix;
    delete mTransformCamera;
    delete mTransformCamera;
@@ -216,19 +217,19 @@ void DisplayList::clearResources() {


void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
    const SkWriter32& writer = recorder.writeStream();
    const SkWriter32& writer = recorder.writeStream();
    init();

    if (writer.size() == 0) {
        mFunctorCount = 0;
        return;
    }


    if (reusing) {
    if (reusing) {
        // re-using display list - clear out previous allocations
        // re-using display list - clear out previous allocations
        clearResources();
        clearResources();
    }
    }

    init();
    initProperties();
    initProperties();


    if (writer.size() == 0) {
        return;
    }

    mSize = writer.size();
    mSize = writer.size();
    void* buffer = sk_malloc_throw(mSize);
    void* buffer = sk_malloc_throw(mSize);
    writer.flatten(buffer);
    writer.flatten(buffer);
@@ -301,6 +302,7 @@ void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorde
void DisplayList::init() {
void DisplayList::init() {
    mSize = 0;
    mSize = 0;
    mIsRenderable = true;
    mIsRenderable = true;
    mFunctorCount = 0;
}
}


size_t DisplayList::getSize() {
size_t DisplayList::getSize() {