hwc: Add NULL check for gralloc private_hnd_t
Add NULL check for private_hnd_t before assigning
to a buffer.
Change-Id: I302be85a68cf024740223faf718081c390f73b61
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 8b38952..acac5b4 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -328,18 +328,20 @@
native_handle_t** handle = va_arg(args, native_handle_t**);
private_handle_t* hnd = (private_handle_t*)native_handle_create(
private_handle_t::sNumFds, private_handle_t::sNumInts());
- hnd->magic = private_handle_t::sMagic;
- hnd->fd = fd;
- hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
- hnd->size = size;
- hnd->offset = offset;
- hnd->base = uint64_t(base) + offset;
- hnd->gpuaddr = 0;
- hnd->width = width;
- hnd->height = height;
- hnd->format = format;
- *handle = (native_handle_t *)hnd;
- res = 0;
+ if (hnd) {
+ hnd->magic = private_handle_t::sMagic;
+ hnd->fd = fd;
+ hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
+ hnd->size = size;
+ hnd->offset = offset;
+ hnd->base = uint64_t(base) + offset;
+ hnd->gpuaddr = 0;
+ hnd->width = width;
+ hnd->height = height;
+ hnd->format = format;
+ *handle = (native_handle_t *)hnd;
+ res = 0;
+ }
break;
}