Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: release NSAlert properly #26100

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions shell/browser/ui/message_box_mac.mm
Expand Up @@ -12,6 +12,7 @@

#include "base/callback.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "shell/browser/native_window.h"
#include "skia/ext/skia_utils_mac.h"
Expand Down Expand Up @@ -94,14 +95,14 @@
} // namespace

int ShowMessageBoxSync(const MessageBoxSettings& settings) {
NSAlert* alert = CreateNSAlert(settings);
base::scoped_nsobject<NSAlert> alert(CreateNSAlert(settings));

// Use runModal for synchronous alert without parent, since we don't have a
// window to wait for. Also use it when window is provided but it is not
// shown as it would be impossible to dismiss the alert if it is connected
// to invisible window (see #22671).
if (!settings.parent_window || !settings.parent_window->IsVisible())
return [[alert autorelease] runModal];
return [alert runModal];

__block int ret_code = -1;

Expand Down Expand Up @@ -140,6 +141,7 @@ void ShowMessageBox(const MessageBoxSettings& settings,
completionHandler:^(NSModalResponse response) {
std::move(callback_).Run(
response, alert.suppressionButton.state == NSOnState);
[alert release];
}];
}
}
Expand Down