libhwui: AnimatedImageThread - UAF

Fix branch subject to UAF.

Bug: 186468053
Test: atest android.graphics.drawable.cts.AnimatedImageDrawableTest
    (w/ UAF detection enabled in libutils Thread)
Change-Id: Idb45f5ef41436920d0ce00f609fa25fb8fdccddf
This commit is contained in:
Steven Moreland
2021-04-27 00:04:38 +00:00
parent d56cd5e5aa
commit 61c3fcf746
2 changed files with 7 additions and 3 deletions

View File

@@ -22,13 +22,16 @@ namespace android {
namespace uirenderer {
AnimatedImageThread& AnimatedImageThread::getInstance() {
static AnimatedImageThread* sInstance = new AnimatedImageThread();
return *sInstance;
[[clang::no_destroy]] static sp<AnimatedImageThread> sInstance = []() {
sp<AnimatedImageThread> thread = sp<AnimatedImageThread>::make();
thread->start("AnimatedImageThread");
return thread;
}();
return *sInstance.get();
}
AnimatedImageThread::AnimatedImageThread() {
setpriority(PRIO_PROCESS, 0, PRIORITY_NORMAL + PRIORITY_MORE_FAVORABLE);
start("AnimatedImageThread");
}
std::future<AnimatedImageDrawable::Snapshot> AnimatedImageThread::decodeNextFrame(

View File

@@ -37,6 +37,7 @@ public:
std::future<AnimatedImageDrawable::Snapshot> reset(const sk_sp<AnimatedImageDrawable>&);
private:
friend sp<AnimatedImageThread>;
AnimatedImageThread();
};