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

Commit 6ef17e36 authored by Sushil Chauhan's avatar Sushil Chauhan Committed by Arne Coucheron
Browse files

Check for strongCount of Surface to avoid double delete in ~Surface()

After binder transaction, keep a check for strongCount of Surface to
avoid creating a sp<Surface> with a surface which is being destroyed
because it will lead to double delete in ~Surface() when it goes out
of scope.

(cherry picked from commit 3f69147188d0ba2607dab084fc04117f5d02d5c7)

Change-Id: I4f67670ac81752113a48200a85ccef4737f25ce7
parent c23a086f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -157,7 +157,13 @@ static void setSurfaceControl(JNIEnv* env, jobject clazz,

static sp<Surface> getSurface(JNIEnv* env, jobject clazz)
{
    sp<Surface> result((Surface*)env->GetIntField(clazz, so.surface));
    Surface* surface = (Surface*)env->GetIntField(clazz, so.surface);
    RefBase* ref = (RefBase*)surface;

    if (ref && ref->getWeakRefs() && (ref->getStrongCount() < 1))
        return NULL; // dead surface

    sp<Surface> result(surface);
    if (result == 0) {
        /*
         * if this method is called from the WindowManager's process, it means