From d46af3075e7b583d267bc86a526815c82d49d113 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 14 Sep 2019 01:14:54 -0400 Subject: [PATCH] app_server: Catch drawing (AGG) allocation exceptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since _DispatchViewDrawingMessage sends single B_ERROR replies in a number of generic cases, doing so here is probably fine; it's much better than crashing, anyway. This is the generalized case of PulkoMandy's earlier patch, which only applied to one drawing operation. This now affects all AGG calls. Change-Id: I751439e43cc300b964ac4cf41c48c1df30baf0a3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1863 Reviewed-by: Stephan Aßmus --- src/servers/app/ServerWindow.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index fcc0f9a24b..8cc29442ca 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -2451,7 +2451,21 @@ fDesktop->LockSingleWindow(); } default: - _DispatchViewDrawingMessage(code, link); + // The drawing code handles allocation failures using exceptions; + // so we need to account for that here. + try { + _DispatchViewDrawingMessage(code, link); + } catch (std::bad_alloc&) { + // Cancel any message we were in the middle of sending. + fLink.CancelMessage(); + + if (link.NeedsReply()) { + // As done in _DispatchViewDrawingMessage, send just a + // single status_t as the reply. + fLink.StartMessage(B_NO_MEMORY); + fLink.Flush(); + } + } break; } }