Commit 663b352f authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

misc: Replace uses of ComPtr::GetAddressOf() with ComPtr::operator&

Microsoft::WRL::ComPtr<T>::GetAddressOf() is banned due to the ease
of causing memory leaks.

Also replace CopyTo(foo.GetAddressOf()) with As(&foo) since CopyTo(&foo)
does not work if we are copying to different interfaces.

Also replace QueryInterface(foo.GetAddressOf()) with
QueryInterface(IID_PPV_ARGS(&foo)).

Tbr: zmo@chromium.org,thestig@chromium.org,juncai@chromium.org,jamiewalch@chromium.org
Bug: 914910
Change-Id: I52739a601332822c33d07a22027d8b15600131aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2271532Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784529}
parent 8aef6a6a
......@@ -149,8 +149,7 @@ bool CreateOrUpdateShortcutLink(const FilePath& shortcut_path,
ShortcutProperties::PROPERTIES_TOAST_ACTIVATOR_CLSID) != 0;
if (has_app_id || has_dual_mode || has_toast_activator_clsid) {
ComPtr<IPropertyStore> property_store;
if (FAILED(i_shell_link.CopyTo(property_store.GetAddressOf())) ||
!property_store.Get())
if (FAILED(i_shell_link.As(&property_store)) || !property_store.Get())
return false;
if (has_app_id && !SetAppIdForPropertyStore(property_store.Get(),
......@@ -218,7 +217,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
ComPtr<IPersistFile> persist;
// Query IShellLink for the IPersistFile interface.
if (FAILED(i_shell_link.CopyTo(persist.GetAddressOf())))
if (FAILED(i_shell_link.As(&persist)))
return false;
// Load the shell link.
......@@ -268,7 +267,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
ShortcutProperties::PROPERTIES_DUAL_MODE |
ShortcutProperties::PROPERTIES_TOAST_ACTIVATOR_CLSID)) {
ComPtr<IPropertyStore> property_store;
if (FAILED(i_shell_link.CopyTo(property_store.GetAddressOf())))
if (FAILED(i_shell_link.As(&property_store)))
return false;
if (options & ShortcutProperties::PROPERTIES_APP_ID) {
......
......@@ -48,7 +48,7 @@ HRESULT CreateIBufferFromData(const uint8_t* data,
return hr;
Microsoft::WRL::ComPtr<IBuffer> internal_buffer;
hr = buffer_factory->Create(length, internal_buffer.GetAddressOf());
hr = buffer_factory->Create(length, &internal_buffer);
if (FAILED(hr))
return hr;
......
......@@ -63,12 +63,11 @@ base::OnceClosure GpuMemoryBufferImplDXGI::AllocateForTesting(
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
HRESULT hr = d3d11_device->CreateTexture2D(&desc, nullptr,
d3d11_texture.GetAddressOf());
HRESULT hr = d3d11_device->CreateTexture2D(&desc, nullptr, &d3d11_texture);
DCHECK(SUCCEEDED(hr));
Microsoft::WRL::ComPtr<IDXGIResource1> dxgi_resource;
hr = d3d11_texture.CopyTo(dxgi_resource.GetAddressOf());
hr = d3d11_texture.As(&dxgi_resource);
DCHECK(SUCCEEDED(hr));
HANDLE texture_handle;
......
......@@ -64,12 +64,11 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer(
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
if (FAILED(d3d11_device->CreateTexture2D(&desc, nullptr,
d3d11_texture.GetAddressOf())))
if (FAILED(d3d11_device->CreateTexture2D(&desc, nullptr, &d3d11_texture)))
return handle;
Microsoft::WRL::ComPtr<IDXGIResource1> dxgi_resource;
if (FAILED(d3d11_texture.CopyTo(dxgi_resource.GetAddressOf())))
if (FAILED(d3d11_texture.As(&dxgi_resource)))
return handle;
HANDLE texture_handle;
......
......@@ -337,8 +337,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
{
Microsoft::WRL::ComPtr<IStream> print_capabilities_stream;
hr = CreateStreamOnHGlobal(nullptr, TRUE,
print_capabilities_stream.GetAddressOf());
hr = CreateStreamOnHGlobal(nullptr, TRUE, &print_capabilities_stream);
DCHECK(SUCCEEDED(hr));
if (print_capabilities_stream.Get()) {
base::win::ScopedBstr error;
......@@ -360,8 +359,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
if (!devmode_out)
return false;
Microsoft::WRL::ComPtr<IStream> printer_defaults_stream;
hr = CreateStreamOnHGlobal(nullptr, TRUE,
printer_defaults_stream.GetAddressOf());
hr = CreateStreamOnHGlobal(nullptr, TRUE, &printer_defaults_stream);
DCHECK(SUCCEEDED(hr));
if (printer_defaults_stream.Get()) {
DWORD dm_size = devmode_out->dmSize + devmode_out->dmDriverExtra;
......
......@@ -439,7 +439,7 @@ std::unique_ptr<DEVMODE, base::FreeDeleter> XpsTicketToDevMode(
return dev_mode;
Microsoft::WRL::ComPtr<IStream> pt_stream;
HRESULT hr = StreamFromPrintTicket(print_ticket, pt_stream.GetAddressOf());
HRESULT hr = StreamFromPrintTicket(print_ticket, &pt_stream);
if (FAILED(hr))
return dev_mode;
......
......@@ -114,7 +114,7 @@ bool AudioCapturerWin::Initialize() {
// Get the audio endpoint.
hr = mm_device_enumerator->GetDefaultAudioEndpoint(eRender, eConsole,
mm_device_.GetAddressOf());
&mm_device_);
if (FAILED(hr)) {
LOG(ERROR) << "Failed to get IMMDevice. Error " << hr;
return false;
......
......@@ -278,13 +278,13 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
// Instantiate the RDP ActiveX control.
result = activex_window.CreateControlEx(
OLESTR("MsTscAx.MsTscAx"), nullptr, nullptr, control.GetAddressOf(),
OLESTR("MsTscAx.MsTscAx"), nullptr, nullptr, &control,
__uuidof(mstsc::IMsTscAxEvents),
reinterpret_cast<IUnknown*>(static_cast<RdpEventsSink*>(this)));
if (FAILED(result))
return LogOnCreateError(result);
result = control.CopyTo(client_.GetAddressOf());
result = control.As(&client_);
if (FAILED(result))
return LogOnCreateError(result);
......@@ -302,7 +302,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
return LogOnCreateError(result);
// Check to see if the platform exposes the interface used for resizing.
result = client_.CopyTo(client_9_.GetAddressOf());
result = client_.As(&client_9_);
if (FAILED(result) && result != E_NOINTERFACE) {
return LogOnCreateError(result);
}
......@@ -313,7 +313,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
return LogOnCreateError(result);
// Fetch IMsRdpClientAdvancedSettings interface for the client.
result = client_->get_AdvancedSettings2(client_settings_.GetAddressOf());
result = client_->get_AdvancedSettings2(&client_settings_);
if (FAILED(result))
return LogOnCreateError(result);
......@@ -367,7 +367,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
if (FAILED(result))
return LogOnCreateError(result);
result = client_->get_SecuredSettings2(secured_settings2.GetAddressOf());
result = client_->get_SecuredSettings2(&secured_settings2);
if (SUCCEEDED(result)) {
result =
secured_settings2->put_AudioRedirectionMode(kRdpAudioModeRedirect);
......@@ -375,7 +375,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
return LogOnCreateError(result);
}
result = client_->get_SecuredSettings(secured_settings.GetAddressOf());
result = client_->get_SecuredSettings(&secured_settings);
if (FAILED(result))
return LogOnCreateError(result);
......@@ -467,7 +467,7 @@ HRESULT RdpClientWindow::OnDisconnected(long reason) {
// Get the error message as well.
base::win::ScopedBstr error_message;
Microsoft::WRL::ComPtr<mstsc::IMsRdpClient5> client5;
result = client_.CopyTo(client5.GetAddressOf());
result = client_.As(&client5);
if (SUCCEEDED(result)) {
result = client5->GetErrorDescription(reason, extended_code,
error_message.Receive());
......
......@@ -389,15 +389,15 @@ Microsoft::WRL::ComPtr<ISensor> PlatformSensorReaderWin32::GetSensorForType(
Microsoft::WRL::ComPtr<ISensorManager> sensor_manager) {
Microsoft::WRL::ComPtr<ISensor> sensor;
Microsoft::WRL::ComPtr<ISensorCollection> sensor_collection;
HRESULT hr = sensor_manager->GetSensorsByType(
sensor_type, sensor_collection.GetAddressOf());
HRESULT hr =
sensor_manager->GetSensorsByType(sensor_type, &sensor_collection);
if (FAILED(hr) || !sensor_collection)
return sensor;
ULONG count = 0;
hr = sensor_collection->GetCount(&count);
if (SUCCEEDED(hr) && count > 0)
sensor_collection->GetAt(0, sensor.GetAddressOf());
sensor_collection->GetAt(0, &sensor);
return sensor;
}
......@@ -484,7 +484,7 @@ bool PlatformSensorReaderWin32::SetReportingInterval(
return false;
Microsoft::WRL::ComPtr<IPortableDeviceValues> return_props;
hr = sensor_->SetProperties(props.Get(), return_props.GetAddressOf());
hr = sensor_->SetProperties(props.Get(), &return_props);
return SUCCEEDED(hr);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment