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

Commit 5a141424 authored by Vic Yang's avatar Vic Yang
Browse files

Fix memory leak in String16

Newly allocated SharedBuffer already has reference count 1, so we
should not call acquire().

Bug: 141764153
Test: Run String16Test.* with ASan that was able to detect the leak
      without this change.
Change-Id: Ib8b1b707b028386d717414d8c5ec5ea7b4b59464
parent 34aba6a6
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -346,7 +346,6 @@ void* String16::edit() {
    if (isStaticString()) {
    if (isStaticString()) {
        buf = static_cast<SharedBuffer*>(alloc((size() + 1) * sizeof(char16_t)));
        buf = static_cast<SharedBuffer*>(alloc((size() + 1) * sizeof(char16_t)));
        if (buf) {
        if (buf) {
            buf->acquire();
            memcpy(buf->data(), mString, (size() + 1) * sizeof(char16_t));
            memcpy(buf->data(), mString, (size() + 1) * sizeof(char16_t));
        }
        }
    } else {
    } else {
@@ -365,7 +364,6 @@ void* String16::editResize(size_t newSize) {
        }
        }
        buf = static_cast<SharedBuffer*>(alloc(newSize));
        buf = static_cast<SharedBuffer*>(alloc(newSize));
        if (buf) {
        if (buf) {
            buf->acquire();
            memcpy(buf->data(), mString, copySize);
            memcpy(buf->data(), mString, copySize);
        }
        }
    } else {
    } else {