From d4ecdf3ced5709d3ba98a5821ac919c45a8dff0a Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Thu, 15 Dec 2022 00:48:42 +0800 Subject: [PATCH] PDFViewer: Avoid errors due to copying of ErrorOr The handle_error took PDFErrorOr objects by value, meaning that their inner values (the error or value stored in the underlying Variant) were somehow copied over. In the first instance where this lambda is called with T = NonnullRefPtr, resulting in funky behavior (invalid NonnullRefPtr state with a VALIDATE fail): if there is no error then the PDFErrorOr copy is destroyed, which might be causing the underlying NonnullRefPtr to be destroyed, but somehow the original in the caller context gets affected and fails verification. The solution seems simple anyway: just pass the value by reference (lvalue or rvalue) so the original object can be used directly, avoiding destruction. --- Userland/Applications/PDFViewer/PDFViewerWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index ee552cd588..2f60ae1a4a 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -338,7 +338,7 @@ void PDFViewerWidget::open_file(Core::File& file) { window()->set_title(DeprecatedString::formatted("{} - PDF Viewer", file.filename())); - auto handle_error = [&](PDF::PDFErrorOr maybe_error) { + auto handle_error = [&](auto&& maybe_error) { if (maybe_error.is_error()) { auto error = maybe_error.release_error(); warnln("{}", error.message());