From 9097400c3294fdc8211342a29aec1f152d8bb57a Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 13 Oct 2023 22:33:36 +0200 Subject: [PATCH] wind: Return more errors to the client when creating windows --- wind/IPC.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wind/IPC.cpp b/wind/IPC.cpp index b251ae3f..fe73a5dc 100644 --- a/wind/IPC.cpp +++ b/wind/IPC.cpp @@ -12,8 +12,6 @@ auto _expr_rc = (expr); \ if (!_expr_rc.has_value()) \ { \ - g_windows.remove(window); \ - delete window; \ os::IPC::send_error(client.conn, _expr_rc.error()); \ return {}; \ } \ @@ -65,9 +63,9 @@ static Result handle_create_window_message(Client& client) request.rect = request.rect.normalized(); - auto name = TRY(String::from_cstring("Window")); + auto name = TRY_OR_IPC_ERROR(String::from_cstring("Window")); - auto shm_path = TRY(String::format("/wind-shm-%d-%lu"_sv, client.conn.fd(), time(NULL))); + auto shm_path = TRY_OR_IPC_ERROR(String::format("/wind-shm-%d-%lu"_sv, client.conn.fd(), time(NULL))); auto* window = new (std::nothrow) Window(request.rect, move(name), request.type); if (!window) @@ -76,12 +74,20 @@ static Result handle_create_window_message(Client& client) return {}; } + auto guard = make_scope_guard([window] { + g_windows.remove(window); + delete window; + }); + window->pixels = (u32*)TRY_OR_IPC_ERROR( os::SharedMemory::create(shm_path.view(), window->contents.height * window->contents.width * 4)); TRY_OR_IPC_ERROR(client.windows.try_append(window)); int id = static_cast(client.windows.size() - 1); + // No more fallible operations, this operation is guaranteed to succeed now. + guard.deactivate(); + window->client = &client; window->id = id;