From 81793808b9347a52dd979e4b3d5d9d10fc8c4915 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Thu, 13 Feb 2025 22:57:24 -0800 Subject: Harden construction sites of android::StrongPointer. Bug: 393217449 Test: presubmit Flag: EXEMPT_refactor Change-Id: Icf703aed608531e9b302b299481af00a52074731 --- libs/gui/BufferQueueProducer.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'libs/gui/BufferQueueProducer.cpp') diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index c241482827..54b3a1f08c 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -693,11 +693,11 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou .requestorName = {mConsumerName.c_str(), mConsumerName.size()}, .extras = std::move(tempOptions), }; - sp graphicBuffer = new GraphicBuffer(allocRequest); + sp graphicBuffer = sp::make(allocRequest); #else sp graphicBuffer = - new GraphicBuffer(width, height, format, BQ_LAYER_COUNT, usage, - {mConsumerName.c_str(), mConsumerName.size()}); + sp::make(width, height, format, BQ_LAYER_COUNT, usage, + std::string{mConsumerName.c_str(), mConsumerName.size()}); #endif status_t error = graphicBuffer->initCheck(); @@ -1464,7 +1464,7 @@ status_t BufferQueueProducer::connect(const sp& listener, #ifndef NO_BINDER if (IInterface::asBinder(listener)->remoteBinder() != nullptr) { status = IInterface::asBinder(listener)->linkToDeath( - static_cast(this)); + sp::fromExisting(this)); if (status != NO_ERROR) { BQ_LOGE("connect: linkToDeath failed: %s (%d)", strerror(-status), status); @@ -1553,8 +1553,7 @@ status_t BufferQueueProducer::disconnect(int api, DisconnectMode mode) { IInterface::asBinder(mCore->mLinkedToDeath); // This can fail if we're here because of the death // notification, but we just ignore it - token->unlinkToDeath( - static_cast(this)); + token->unlinkToDeath(sp::fromExisting(this)); } #endif mCore->mSharedBufferSlot = @@ -1685,11 +1684,11 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, #endif #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) - sp graphicBuffer = new GraphicBuffer(allocRequest); + sp graphicBuffer = sp::make(allocRequest); #else - sp graphicBuffer = new GraphicBuffer( - allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT, - allocUsage, allocName); + sp graphicBuffer = + sp::make(allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT, + allocUsage, allocName); #endif status_t result = graphicBuffer->initCheck(); -- cgit v1.2.3-59-g8ed1b