Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a2e1ce8 authored by George Burgess IV's avatar George Burgess IV
Browse files

nativewindow: report errors on error to allocate a handle

At the moment, `outBuffer` won't be set if `err == 0 && gbuffer->handle
!= nullptr`, even though we return a zero value for `err`. This causes
us to pass nullptr to AHardwareBuffer_release in
AHardwareBuffer_isSupported, which isn't correct.

Caught by the static analyzer:

> frameworks/native/libs/nativewindow/AHardwareBuffer.cpp:394:9:
warning: Null passed to a callee that requires a non-null 1st parameter
[clang-analyzer-nullability.NullPassedToNonnull]

This also replaces 0 with nullptr, since we're checking a pointer's
value here.

Bug: None
Test: TreeHugger
Change-Id: Id2fad234f98eda71b06419193e15cbfb5fa39bf1
parent da4a5ca5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -51,13 +51,13 @@ int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc, AHardwareBuffer**
            std::string("AHardwareBuffer pid [") + std::to_string(getpid()) + "]"));

    status_t err = gbuffer->initCheck();
    if (err != 0 || gbuffer->handle == 0) {
    if (err != 0 || gbuffer->handle == nullptr) {
        if (err == NO_MEMORY) {
            GraphicBuffer::dumpAllocationsToSystemLog();
        }
        ALOGE("GraphicBuffer(w=%u, h=%u, lc=%u) failed (%s), handle=%p",
                desc->width, desc->height, desc->layers, strerror(-err), gbuffer->handle);
        return err;
        return err == 0 ? UNKNOWN_ERROR : err;
    }

    *outBuffer = AHardwareBuffer_from_GraphicBuffer(gbuffer.get());