1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:27:42 +00:00

PDFViewer: Avoid errors due to copying of ErrorOr

The handle_error took PDFErrorOr<T> 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<T> 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.
This commit is contained in:
Rodrigo Tobar 2022-12-15 00:48:42 +08:00 committed by Andreas Kling
parent 124ab5bec6
commit d4ecdf3ced

View file

@ -338,7 +338,7 @@ void PDFViewerWidget::open_file(Core::File& file)
{
window()->set_title(DeprecatedString::formatted("{} - PDF Viewer", file.filename()));
auto handle_error = [&]<typename T>(PDF::PDFErrorOr<T> maybe_error) {
auto handle_error = [&](auto&& maybe_error) {
if (maybe_error.is_error()) {
auto error = maybe_error.release_error();
warnln("{}", error.message());