diff --git a/liboverlay/overlayLib.cpp b/liboverlay/overlayLib.cpp index 3d1c859..ba98e23 100755 --- a/liboverlay/overlayLib.cpp +++ b/liboverlay/overlayLib.cpp @@ -1841,7 +1841,8 @@ bool OverlayDataChannel::mapRotatorMemory(int num_buffers, bool uiChannel, int r //XXX: getInstance(false) implies that it should only // use the kernel allocator. Change it to something // more descriptive later. - android::sp allocController = gralloc::IAllocController::getInstance(false); + android::sp allocController = + gralloc::IAllocController::getInstance(false); int err = allocController->allocate(data, allocFlags, 0); if(err) { reportError("Cant allocate rotatory memory"); @@ -1899,12 +1900,7 @@ bool OverlayDataChannel::closeDataChannel() { return true; if (!mNoRot && mRotFD > 0) { - //XXX: getInstance(false) implies that it should only - // use the kernel allocator. Change it to something - // more descriptive later. - android::sp allocController = gralloc::IAllocController::getInstance(false); - sp memalloc = allocController->getAllocator(mBufferType); - memalloc->free_buffer(mPmemAddr, mPmemOffset * mNumBuffers, 0, mPmemFD); + freeRotatorMemory(mPmemAddr, mPmemOffset, mPmemFD); close(mPmemFD); mPmemFD = -1; close(mRotFD); @@ -1922,6 +1918,23 @@ bool OverlayDataChannel::closeDataChannel() { return true; } +bool OverlayDataChannel::freeRotatorMemory(void* pmemAddr, uint32_t + pmemOffset, int pmemFD) { + bool ret = true; + if(pmemFD != -1 && pmemAddr != MAP_FAILED) { + //XXX: getInstance(false) implies that it should only + // use the kernel allocator. Change it to something + // more descriptive later. + android::sp allocController = + gralloc::IAllocController::getInstance(false); + sp memalloc = allocController->getAllocator(mBufferType); + memalloc->free_buffer(pmemAddr, pmemOffset * mNumBuffers, 0, pmemFD); + } + else + ret = false; + return ret; +} + bool OverlayDataChannel::setFd(int fd) { mOvData.data.memory_id = fd; return true; @@ -1948,6 +1961,8 @@ bool OverlayDataChannel::queueBuffer(uint32_t offset) { result = mapRotatorMemory(mNumBuffers, 0, UPDATE_REQUEST); if (!result) { LOGE("queueBuffer: mapRotatorMemory failed"); + // free the oldPmemAddr if any + freeRotatorMemory(oldPmemAddr, oldPmemOffset, oldPmemFD); return false; } mUpdateDataChannel = false; @@ -1957,15 +1972,7 @@ bool OverlayDataChannel::queueBuffer(uint32_t offset) { result = queue(offset); // Unmap the old PMEM memory after the queueBuffer has returned - if (oldPmemFD != -1 && oldPmemAddr != MAP_FAILED) { - //XXX: getInstance(false) implies that it should only - // use the kernel allocator. Change it to something - // more descriptive later. - android::sp allocController = gralloc::IAllocController::getInstance(false); - sp memalloc = allocController->getAllocator(mBufferType); - memalloc->free_buffer(oldPmemAddr, oldPmemOffset * mNumBuffers, 0, oldPmemFD); - oldPmemFD = -1; - } + freeRotatorMemory(oldPmemAddr, oldPmemOffset, oldPmemFD); return result; } diff --git a/liboverlay/overlayLib.h b/liboverlay/overlayLib.h index e55a6a8..639d584 100755 --- a/liboverlay/overlayLib.h +++ b/liboverlay/overlayLib.h @@ -367,6 +367,7 @@ class OverlayDataChannel { bool openDevices(int fbnum = -1, bool uichannel = false, int num_buffers = 2); bool mapRotatorMemory(int num_buffers, bool uiChannel, int requestType); bool queue(uint32_t offset); + bool freeRotatorMemory(void *pmemAddr, uint32_t pmemOffset, int pmemFD); public: OverlayDataChannel();