fix: release NSAlert properly (#26078)
This commit is contained in:
parent
f93e33528e
commit
e3c4bbd21f
1 changed files with 4 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "base/mac/mac_util.h"
|
#include "base/mac/mac_util.h"
|
||||||
|
#include "base/mac/scoped_nsobject.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "skia/ext/skia_utils_mac.h"
|
#include "skia/ext/skia_utils_mac.h"
|
||||||
|
@ -94,14 +95,14 @@ NSAlert* CreateNSAlert(const MessageBoxSettings& settings) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int ShowMessageBoxSync(const MessageBoxSettings& settings) {
|
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
|
// 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
|
// 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
|
// shown as it would be impossible to dismiss the alert if it is connected
|
||||||
// to invisible window (see #22671).
|
// to invisible window (see #22671).
|
||||||
if (!settings.parent_window || !settings.parent_window->IsVisible())
|
if (!settings.parent_window || !settings.parent_window->IsVisible())
|
||||||
return [[alert autorelease] runModal];
|
return [alert runModal];
|
||||||
|
|
||||||
__block int ret_code = -1;
|
__block int ret_code = -1;
|
||||||
|
|
||||||
|
@ -140,6 +141,7 @@ void ShowMessageBox(const MessageBoxSettings& settings,
|
||||||
completionHandler:^(NSModalResponse response) {
|
completionHandler:^(NSModalResponse response) {
|
||||||
std::move(callback_).Run(
|
std::move(callback_).Run(
|
||||||
response, alert.suppressionButton.state == NSOnState);
|
response, alert.suppressionButton.state == NSOnState);
|
||||||
|
[alert release];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue