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

Commit 75e93e7b authored by Ray Essick's avatar Ray Essick
Browse files

Avoid returning value on stack

AMediaFormat_getString() returnes a string not guaranteed to live beyond
the call. The underlying implementation of String8 seems to have made
this safe by using SharedBuffers, but that's luck of the implementatoon,
not a guarantee of the API.  We instead get our value by chasing through
where we just added it to the longer-lived vector.

Bug: 193904641
Test: atest libmedkandk_test
Test: atest android.mediav2.cts.MediaFormatUnitTest (master)
Change-Id: I7df35b7dbccf24c72cfd977a6b13d85aee8ae555
parent 1c3c35c0
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -200,8 +200,11 @@ bool AMediaFormat_getString(AMediaFormat* mData, const char *name, const char **
    AString tmp;
    if (mData->mFormat->findString(name, &tmp)) {
        String8 ret(tmp.c_str());
        mData->mStringCache.add(String8(name), ret);
        *out = ret.string();
        ssize_t i = mData->mStringCache.add(String8(name), ret);
        if (i < 0) {
            return false;
        }
        *out = mData->mStringCache.valueAt(i).string();
        return true;
    }
    return false;