gpu_display: don't dereference NULL if alloc fails

dwl_context_new() did not check if the allocation failed before using
the returned pointer.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: Ibeb0fb0b0a6e434657f09f8c24a7bd6ff7f8c21a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5634619
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
This commit is contained in:
Daniel Verkamp 2024-06-14 14:21:21 -07:00 committed by crosvm LUCI
parent 9227b78c4f
commit 51cf0f429d

View file

@ -723,6 +723,8 @@ static void error_callback_stub(const char *message) {
struct dwl_context *dwl_context_new(dwl_error_callback_type error_callback)
{
struct dwl_context *ctx = calloc(1, sizeof(struct dwl_context));
if (!ctx)
return NULL;
ctx->ifaces.context = ctx;
ctx->error_callback = error_callback ? error_callback : error_callback_stub;
return ctx;