fix a crasher when running out of memory

MemoryHeapBase::getBase() returns MAP_FAILED in case or
OOM, not null which is what SF was checking against.

This addresses one of the issues of bug 7230543.

Bug: 7230543
Change-Id: I763a88f64a2f9ff75eb139cfbaf9a1a9746c5577
This commit is contained in:
Mathias Agopian 2012-09-25 15:28:44 -07:00
parent bb53b0e4b9
commit 7b19051137
2 changed files with 5 additions and 2 deletions

View File

@ -58,10 +58,13 @@ public:
/* implement IMemoryHeap interface */ /* implement IMemoryHeap interface */
virtual int getHeapID() const; virtual int getHeapID() const;
/* virtual address of the heap. returns MAP_FAILED in case of error */
virtual void* getBase() const; virtual void* getBase() const;
virtual size_t getSize() const; virtual size_t getSize() const;
virtual uint32_t getFlags() const; virtual uint32_t getFlags() const;
virtual uint32_t getOffset() const; virtual uint32_t getOffset() const;
const char* getDevice() const; const char* getDevice() const;

View File

@ -2497,7 +2497,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(const sp<IBinder>& display,
sp<MemoryHeapBase> base( sp<MemoryHeapBase> base(
new MemoryHeapBase(size, 0, "screen-capture") ); new MemoryHeapBase(size, 0, "screen-capture") );
void* const ptr = base->getBase(); void* const ptr = base->getBase();
if (ptr) { if (ptr != MAP_FAILED) {
// capture the screen with glReadPixels() // capture the screen with glReadPixels()
ScopedTrace _t(ATRACE_TAG, "glReadPixels"); ScopedTrace _t(ATRACE_TAG, "glReadPixels");
glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr); glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr);