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

Commit afa728e0 authored by Robert Shih's avatar Robert Shih Committed by android-build-merger
Browse files

DO NOT MERGE Don't leak `this` out of GraphicBufferSource ctor

am: ebeb4700

Change-Id: I1ae0603aa9b798bd6c624d96c18ef6457212bfa7
parents e4b59cb2 ebeb4700
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -170,9 +170,12 @@ GraphicBufferSource::GraphicBufferSource(
        mIsPersistent = true;
    }
    mConsumer->setDefaultBufferSize(bufferWidth, bufferHeight);
    // Note that we can't create an sp<...>(this) in a ctor that will not keep a
    // reference once the ctor ends, as that would cause the refcount of 'this'
    // dropping to 0 at the end of the ctor.  Since all we need is a wp<...>
}

status_t GraphicBufferSource::init() {
    // Note that we can't create an sp<...>(this) in a method that will not keep a
    // reference once the method ends, as that may cause the refcount of 'this'
    // dropping to 0 at the end of the method.  Since all we need is a wp<...>
    // that's what we create.
    wp<BufferQueue::ConsumerListener> listener = static_cast<BufferQueue::ConsumerListener*>(this);
    sp<IConsumerListener> proxy;
@@ -186,10 +189,9 @@ GraphicBufferSource::GraphicBufferSource(
    if (mInitCheck != NO_ERROR) {
        ALOGE("Error connecting to BufferQueue: %s (%d)",
                strerror(-mInitCheck), mInitCheck);
        return;
    }

    CHECK(mInitCheck == NO_ERROR);
    return mInitCheck;
}

GraphicBufferSource::~GraphicBufferSource() {
+1 −5
Original line number Diff line number Diff line
@@ -61,11 +61,7 @@ public:

    virtual ~GraphicBufferSource();

    // We can't throw an exception if the constructor fails, so we just set
    // this and require that the caller test the value.
    status_t initCheck() const {
        return mInitCheck;
    }
    status_t init();

    // Returns the handle to the producer side of the BufferQueue.  Buffers
    // queued on this will be received by GraphicBufferSource.
+1 −1
Original line number Diff line number Diff line
@@ -1046,7 +1046,7 @@ status_t OMXNodeInstance::createGraphicBufferSource(
            usageBits,
            bufferConsumer);

    if ((err = bufferSource->initCheck()) != OK) {
    if ((err = bufferSource->init()) != OK) {
        return err;
    }
    setGraphicBufferSource(bufferSource);