From a186b47650f21acf6be2dcf8f730ae0057eef075 Mon Sep 17 00:00:00 2001 From: Naseer Ahmed Date: Fri, 7 Jul 2017 18:50:49 -0400 Subject: [PATCH] gralloc1: Do not do early validation on Release Check if handle exists in map first. CRs-Fixed: 2074655 Change-Id: Ia928f1f09578b9ab21479ce237a56555f29ca9c5 --- libgralloc1/gr_buf_mgr.cpp | 10 ++++++++-- libgralloc1/gr_device_impl.cpp | 11 +++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libgralloc1/gr_buf_mgr.cpp b/libgralloc1/gr_buf_mgr.cpp index 2c240019..bb37da0b 100644 --- a/libgralloc1/gr_buf_mgr.cpp +++ b/libgralloc1/gr_buf_mgr.cpp @@ -192,7 +192,13 @@ void BufferManager::CreateSharedHandle(buffer_handle_t inbuffer, const BufferDes gralloc1_error_t BufferManager::FreeBuffer(std::shared_ptr buf) { auto hnd = buf->handle; - ALOGD_IF(DEBUG, "FreeBuffer handle:%p id: %" PRIu64, hnd, hnd->id); + ALOGD_IF(DEBUG, "FreeBuffer handle:%p", hnd); + + if (private_handle_t::validate(hnd) != 0) { + ALOGE("FreeBuffer: Invalid handle: %p", hnd); + return GRALLOC1_ERROR_BAD_HANDLE; + } + if (allocator_->FreeBuffer(reinterpret_cast(hnd->base), hnd->size, hnd->offset, hnd->fd, buf->ion_handle_main) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; @@ -284,7 +290,7 @@ gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) { } gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) { - ALOGD_IF(DEBUG, "Release buffer handle:%p id: %" PRIu64, hnd, hnd->id); + ALOGD_IF(DEBUG, "Release buffer handle:%p", hnd); std::lock_guard lock(buffer_lock_); auto buf = GetBufferFromHandleLocked(hnd); if (buf == nullptr) { diff --git a/libgralloc1/gr_device_impl.cpp b/libgralloc1/gr_device_impl.cpp index ee900908..03e42ab9 100644 --- a/libgralloc1/gr_device_impl.cpp +++ b/libgralloc1/gr_device_impl.cpp @@ -392,14 +392,13 @@ gralloc1_error_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_han } gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - GrallocImpl const *dev = GRALLOC_IMPL(device); - status = dev->buf_mgr_->ReleaseBuffer(hnd); + if (!device || !buffer) { + return GRALLOC1_ERROR_BAD_DESCRIPTOR; } - return status; + const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); + GrallocImpl const *dev = GRALLOC_IMPL(device); + return dev->buf_mgr_->ReleaseBuffer(hnd); } gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,