From 5258c21c1bdeb412c4ad7982d95e587a121f00fc Mon Sep 17 00:00:00 2001 From: Rebecca Schultz Zavin Date: Thu, 4 Oct 2012 11:23:56 -0700 Subject: [PATCH] Fix bug in gralloc If buffers were allocated and then locked without ever being passed to another process lock would return NULL instead of a pointer to the buffer. Instead map the buffer from lock if it hasn't already been done by register. Also check in free and unmap the buffer it is mapped. Change-Id: I3fe670ccb429f3de5f2e4dd07768414e70a02036 Signed-off-by: Rebecca Schultz Zavin --- gralloc/gralloc.cpp | 2 ++ gralloc/mapper.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/gralloc/gralloc.cpp b/gralloc/gralloc.cpp index cb4cb5b..e28c005 100644 --- a/gralloc/gralloc.cpp +++ b/gralloc/gralloc.cpp @@ -356,6 +356,8 @@ static int gralloc_free(alloc_device_t* dev, private_handle_t const* hnd = reinterpret_cast(handle); gralloc_module_t* module = reinterpret_cast( dev->common.module); + if (hnd->base) + grallocUnmap(module, const_cast(hnd)); close(hnd->fd); if (hnd->fd1 >= 0) diff --git a/gralloc/mapper.cpp b/gralloc/mapper.cpp index 0e7b8b9..e63f749 100644 --- a/gralloc/mapper.cpp +++ b/gralloc/mapper.cpp @@ -164,6 +164,8 @@ int gralloc_lock(gralloc_module_t const* module, return -EINVAL; private_handle_t* hnd = (private_handle_t*)handle; + if (!hnd->base) + gralloc_map(module, hnd); *vaddr = (void*)hnd->base; return 0; } -- 2.20.1