libgralloc-qsd8k: Close the masterFd when freeing video/camera buffers
Buffers allocated from the adsp or smipool regions have a masterFd associated with each buffer. Make sure both the fds are closed when the buffers are freed to avoid memory leaks. Change-Id: I7dd194bae9ebfffb5e8c1ed647bff6210409a731
This commit is contained in:
parent
27a57f3a80
commit
3be64f08f9
@ -168,6 +168,7 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t*
|
||||
// the PmemAllocator rather than getting the base & offset separately
|
||||
int offset = 0;
|
||||
int lockState = 0;
|
||||
int masterFd = -1;
|
||||
size = roundUpToPageSize(size);
|
||||
#ifndef USE_ASHMEM
|
||||
if (usage & GRALLOC_USAGE_HW_TEXTURE) {
|
||||
@ -217,7 +218,7 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t*
|
||||
// PMEM buffers are always mmapped
|
||||
lockState |= private_handle_t::LOCK_STATE_MAPPED;
|
||||
|
||||
err = pma->alloc_pmem_buffer(size, usage, &base, &offset, &fd);
|
||||
err = pma->alloc_pmem_buffer(size, usage, &base, &offset, &fd, &masterFd);
|
||||
if (err < 0) {
|
||||
if (((usage & GRALLOC_USAGE_HW_MASK) == 0) &&
|
||||
((usage & GRALLOC_USAGE_PRIVATE_PMEM_ADSP) == 0)) {
|
||||
@ -243,6 +244,7 @@ try_ashmem:
|
||||
hnd->offset = offset;
|
||||
hnd->base = int(base)+offset;
|
||||
hnd->lockState = lockState;
|
||||
hnd->masterFd = masterFd;
|
||||
*pHandle = hnd;
|
||||
}
|
||||
|
||||
@ -393,7 +395,7 @@ int gpu_context_t::free_impl(private_handle_t const* hnd) {
|
||||
const size_t bufferSize = m->finfo.line_length * m->info.yres;
|
||||
int index = (hnd->base - m->framebuffer->base) / bufferSize;
|
||||
m->bufferMask &= ~(1<<index);
|
||||
} else {
|
||||
} else {
|
||||
PmemAllocator* pmem_allocator = 0;
|
||||
if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_PMEM) {
|
||||
pmem_allocator = &pmemAllocator;
|
||||
@ -404,10 +406,14 @@ int gpu_context_t::free_impl(private_handle_t const* hnd) {
|
||||
pmem_allocator->free_pmem_buffer(hnd->size, (void*)hnd->base,
|
||||
hnd->offset, hnd->fd);
|
||||
}
|
||||
|
||||
deps.terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
|
||||
}
|
||||
|
||||
deps.close(hnd->fd);
|
||||
if (hnd->masterFd != -1) {
|
||||
deps.close(hnd->masterFd);
|
||||
}
|
||||
delete hnd; // XXX JMG: move this to the deps
|
||||
return 0;
|
||||
}
|
||||
|
@ -269,16 +269,17 @@ struct private_handle_t {
|
||||
int format;
|
||||
int width;
|
||||
int height;
|
||||
int masterFd;
|
||||
|
||||
#ifdef __cplusplus
|
||||
static const int sNumInts = 13;
|
||||
static const int sNumInts = 14;
|
||||
static const int sNumFds = 1;
|
||||
static const int sMagic = 'gmsm';
|
||||
|
||||
private_handle_t(int fd, int size, int flags, int bufferType, int format, int width, int height) :
|
||||
fd(fd), magic(sMagic), flags(flags), size(size), offset(0), bufferType(bufferType),
|
||||
base(0), lockState(0), writeOwner(0), gpuaddr(0), pid(getpid()), format(format), width(width),
|
||||
height(height)
|
||||
height(height), masterFd(-1)
|
||||
{
|
||||
version = sizeof(native_handle);
|
||||
numInts = sNumInts;
|
||||
|
@ -143,7 +143,7 @@ int PmemUserspaceAllocator::init_pmem_area()
|
||||
|
||||
|
||||
int PmemUserspaceAllocator::alloc_pmem_buffer(size_t size, int usage,
|
||||
void** pBase, int* pOffset, int* pFd)
|
||||
void** pBase, int* pOffset, int* pFd, int* masterFd)
|
||||
{
|
||||
BEGIN_FUNC;
|
||||
int err = init_pmem_area();
|
||||
@ -185,6 +185,7 @@ int PmemUserspaceAllocator::alloc_pmem_buffer(size_t size, int usage,
|
||||
*pBase = base;
|
||||
*pOffset = offset;
|
||||
*pFd = fd;
|
||||
*masterFd = -1;
|
||||
}
|
||||
//LOGD_IF(!err, "%s: allocating pmem size=%d, offset=%d", pmemdev, size, offset);
|
||||
}
|
||||
@ -259,7 +260,7 @@ static unsigned clp2(unsigned x) {
|
||||
|
||||
|
||||
int PmemKernelAllocator::alloc_pmem_buffer(size_t size, int usage,
|
||||
void** pBase,int* pOffset, int* pFd)
|
||||
void** pBase,int* pOffset, int* pFd, int* masterFd)
|
||||
{
|
||||
BEGIN_FUNC;
|
||||
|
||||
@ -320,6 +321,7 @@ int PmemKernelAllocator::alloc_pmem_buffer(size_t size, int usage,
|
||||
*pBase = base;
|
||||
*pOffset = 0;
|
||||
*pFd = fd;
|
||||
*masterFd = master_fd;
|
||||
} else {
|
||||
deps.munmap(base, size);
|
||||
deps.unmapPmem(fd, offset, size);
|
||||
@ -346,12 +348,7 @@ int PmemKernelAllocator::free_pmem_buffer(size_t size, void* base, int offset, i
|
||||
LOGW("error unmapping pmem fd: %s", strerror(err));
|
||||
return -err;
|
||||
}
|
||||
err = deps.munmap(base, size);
|
||||
if (err < 0) {
|
||||
err = deps.getErrno();
|
||||
LOGW("error unmapping pmem master_fd: %s", strerror(err));
|
||||
return -err;
|
||||
}
|
||||
|
||||
END_FUNC;
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class PmemAllocator {
|
||||
virtual void* get_base_address() = 0;
|
||||
|
||||
virtual int alloc_pmem_buffer(size_t size, int usage, void** pBase,
|
||||
int* pOffset, int* pFd) = 0;
|
||||
int* pOffset, int* pFd, int* masterFd) = 0;
|
||||
virtual int free_pmem_buffer(size_t size, void* base, int offset, int fd) = 0;
|
||||
};
|
||||
|
||||
@ -89,7 +89,7 @@ class PmemUserspaceAllocator: public PmemAllocator {
|
||||
virtual int init_pmem_area_locked();
|
||||
virtual int init_pmem_area();
|
||||
virtual int alloc_pmem_buffer(size_t size, int usage, void** pBase,
|
||||
int* pOffset, int* pFd);
|
||||
int* pOffset, int* pFd, int* masterFd);
|
||||
virtual int free_pmem_buffer(size_t size, void* base, int offset, int fd);
|
||||
|
||||
#ifndef ANDROID_OS
|
||||
@ -151,7 +151,7 @@ class PmemKernelAllocator: public PmemAllocator {
|
||||
virtual void* get_base_address();
|
||||
|
||||
virtual int alloc_pmem_buffer(size_t size, int usage, void** pBase,
|
||||
int* pOffset, int* pFd);
|
||||
int* pOffset, int* pFd, int* masterFd);
|
||||
virtual int free_pmem_buffer(size_t size, void* base, int offset, int fd);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user