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, ...@@ -149,8 +149,7 @@ bool CreateOrUpdateShortcutLink(const FilePath& shortcut_path,
ShortcutProperties::PROPERTIES_TOAST_ACTIVATOR_CLSID) != 0; ShortcutProperties::PROPERTIES_TOAST_ACTIVATOR_CLSID) != 0;
if (has_app_id || has_dual_mode || has_toast_activator_clsid) { if (has_app_id || has_dual_mode || has_toast_activator_clsid) {
ComPtr<IPropertyStore> property_store; ComPtr<IPropertyStore> property_store;
if (FAILED(i_shell_link.CopyTo(property_store.GetAddressOf())) || if (FAILED(i_shell_link.As(&property_store)) || !property_store.Get())
!property_store.Get())
return false; return false;
if (has_app_id && !SetAppIdForPropertyStore(property_store.Get(), if (has_app_id && !SetAppIdForPropertyStore(property_store.Get(),
...@@ -218,7 +217,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path, ...@@ -218,7 +217,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
ComPtr<IPersistFile> persist; ComPtr<IPersistFile> persist;
// Query IShellLink for the IPersistFile interface. // Query IShellLink for the IPersistFile interface.
if (FAILED(i_shell_link.CopyTo(persist.GetAddressOf()))) if (FAILED(i_shell_link.As(&persist)))
return false; return false;
// Load the shell link. // Load the shell link.
...@@ -268,7 +267,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path, ...@@ -268,7 +267,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
ShortcutProperties::PROPERTIES_DUAL_MODE | ShortcutProperties::PROPERTIES_DUAL_MODE |
ShortcutProperties::PROPERTIES_TOAST_ACTIVATOR_CLSID)) { ShortcutProperties::PROPERTIES_TOAST_ACTIVATOR_CLSID)) {
ComPtr<IPropertyStore> property_store; ComPtr<IPropertyStore> property_store;
if (FAILED(i_shell_link.CopyTo(property_store.GetAddressOf()))) if (FAILED(i_shell_link.As(&property_store)))
return false; return false;
if (options & ShortcutProperties::PROPERTIES_APP_ID) { if (options & ShortcutProperties::PROPERTIES_APP_ID) {
......
...@@ -48,7 +48,7 @@ HRESULT CreateIBufferFromData(const uint8_t* data, ...@@ -48,7 +48,7 @@ HRESULT CreateIBufferFromData(const uint8_t* data,
return hr; return hr;
Microsoft::WRL::ComPtr<IBuffer> internal_buffer; Microsoft::WRL::ComPtr<IBuffer> internal_buffer;
hr = buffer_factory->Create(length, internal_buffer.GetAddressOf()); hr = buffer_factory->Create(length, &internal_buffer);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
......
...@@ -63,12 +63,11 @@ base::OnceClosure GpuMemoryBufferImplDXGI::AllocateForTesting( ...@@ -63,12 +63,11 @@ base::OnceClosure GpuMemoryBufferImplDXGI::AllocateForTesting(
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture; Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
HRESULT hr = d3d11_device->CreateTexture2D(&desc, nullptr, HRESULT hr = d3d11_device->CreateTexture2D(&desc, nullptr, &d3d11_texture);
d3d11_texture.GetAddressOf());
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
Microsoft::WRL::ComPtr<IDXGIResource1> dxgi_resource; Microsoft::WRL::ComPtr<IDXGIResource1> dxgi_resource;
hr = d3d11_texture.CopyTo(dxgi_resource.GetAddressOf()); hr = d3d11_texture.As(&dxgi_resource);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
HANDLE texture_handle; HANDLE texture_handle;
......
...@@ -64,12 +64,11 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer( ...@@ -64,12 +64,11 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer(
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture; Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
if (FAILED(d3d11_device->CreateTexture2D(&desc, nullptr, if (FAILED(d3d11_device->CreateTexture2D(&desc, nullptr, &d3d11_texture)))
d3d11_texture.GetAddressOf())))
return handle; return handle;
Microsoft::WRL::ComPtr<IDXGIResource1> dxgi_resource; Microsoft::WRL::ComPtr<IDXGIResource1> dxgi_resource;
if (FAILED(d3d11_texture.CopyTo(dxgi_resource.GetAddressOf()))) if (FAILED(d3d11_texture.As(&dxgi_resource)))
return handle; return handle;
HANDLE texture_handle; HANDLE texture_handle;
......
...@@ -337,8 +337,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( ...@@ -337,8 +337,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
{ {
Microsoft::WRL::ComPtr<IStream> print_capabilities_stream; Microsoft::WRL::ComPtr<IStream> print_capabilities_stream;
hr = CreateStreamOnHGlobal(nullptr, TRUE, hr = CreateStreamOnHGlobal(nullptr, TRUE, &print_capabilities_stream);
print_capabilities_stream.GetAddressOf());
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
if (print_capabilities_stream.Get()) { if (print_capabilities_stream.Get()) {
base::win::ScopedBstr error; base::win::ScopedBstr error;
...@@ -360,8 +359,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( ...@@ -360,8 +359,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
if (!devmode_out) if (!devmode_out)
return false; return false;
Microsoft::WRL::ComPtr<IStream> printer_defaults_stream; Microsoft::WRL::ComPtr<IStream> printer_defaults_stream;
hr = CreateStreamOnHGlobal(nullptr, TRUE, hr = CreateStreamOnHGlobal(nullptr, TRUE, &printer_defaults_stream);
printer_defaults_stream.GetAddressOf());
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
if (printer_defaults_stream.Get()) { if (printer_defaults_stream.Get()) {
DWORD dm_size = devmode_out->dmSize + devmode_out->dmDriverExtra; DWORD dm_size = devmode_out->dmSize + devmode_out->dmDriverExtra;
......
...@@ -439,7 +439,7 @@ std::unique_ptr<DEVMODE, base::FreeDeleter> XpsTicketToDevMode( ...@@ -439,7 +439,7 @@ std::unique_ptr<DEVMODE, base::FreeDeleter> XpsTicketToDevMode(
return dev_mode; return dev_mode;
Microsoft::WRL::ComPtr<IStream> pt_stream; Microsoft::WRL::ComPtr<IStream> pt_stream;
HRESULT hr = StreamFromPrintTicket(print_ticket, pt_stream.GetAddressOf()); HRESULT hr = StreamFromPrintTicket(print_ticket, &pt_stream);
if (FAILED(hr)) if (FAILED(hr))
return dev_mode; return dev_mode;
......
...@@ -114,7 +114,7 @@ bool AudioCapturerWin::Initialize() { ...@@ -114,7 +114,7 @@ bool AudioCapturerWin::Initialize() {
// Get the audio endpoint. // Get the audio endpoint.
hr = mm_device_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, hr = mm_device_enumerator->GetDefaultAudioEndpoint(eRender, eConsole,
mm_device_.GetAddressOf()); &mm_device_);
if (FAILED(hr)) { if (FAILED(hr)) {
LOG(ERROR) << "Failed to get IMMDevice. Error " << hr; LOG(ERROR) << "Failed to get IMMDevice. Error " << hr;
return false; return false;
......
...@@ -278,13 +278,13 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) { ...@@ -278,13 +278,13 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
// Instantiate the RDP ActiveX control. // Instantiate the RDP ActiveX control.
result = activex_window.CreateControlEx( result = activex_window.CreateControlEx(
OLESTR("MsTscAx.MsTscAx"), nullptr, nullptr, control.GetAddressOf(), OLESTR("MsTscAx.MsTscAx"), nullptr, nullptr, &control,
__uuidof(mstsc::IMsTscAxEvents), __uuidof(mstsc::IMsTscAxEvents),
reinterpret_cast<IUnknown*>(static_cast<RdpEventsSink*>(this))); reinterpret_cast<IUnknown*>(static_cast<RdpEventsSink*>(this)));
if (FAILED(result)) if (FAILED(result))
return LogOnCreateError(result); return LogOnCreateError(result);
result = control.CopyTo(client_.GetAddressOf()); result = control.As(&client_);
if (FAILED(result)) if (FAILED(result))
return LogOnCreateError(result); return LogOnCreateError(result);
...@@ -302,7 +302,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) { ...@@ -302,7 +302,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
return LogOnCreateError(result); return LogOnCreateError(result);
// Check to see if the platform exposes the interface used for resizing. // 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) { if (FAILED(result) && result != E_NOINTERFACE) {
return LogOnCreateError(result); return LogOnCreateError(result);
} }
...@@ -313,7 +313,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) { ...@@ -313,7 +313,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
return LogOnCreateError(result); return LogOnCreateError(result);
// Fetch IMsRdpClientAdvancedSettings interface for the client. // Fetch IMsRdpClientAdvancedSettings interface for the client.
result = client_->get_AdvancedSettings2(client_settings_.GetAddressOf()); result = client_->get_AdvancedSettings2(&client_settings_);
if (FAILED(result)) if (FAILED(result))
return LogOnCreateError(result); return LogOnCreateError(result);
...@@ -367,7 +367,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) { ...@@ -367,7 +367,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
if (FAILED(result)) if (FAILED(result))
return LogOnCreateError(result); return LogOnCreateError(result);
result = client_->get_SecuredSettings2(secured_settings2.GetAddressOf()); result = client_->get_SecuredSettings2(&secured_settings2);
if (SUCCEEDED(result)) { if (SUCCEEDED(result)) {
result = result =
secured_settings2->put_AudioRedirectionMode(kRdpAudioModeRedirect); secured_settings2->put_AudioRedirectionMode(kRdpAudioModeRedirect);
...@@ -375,7 +375,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) { ...@@ -375,7 +375,7 @@ LRESULT RdpClientWindow::OnCreate(CREATESTRUCT* create_struct) {
return LogOnCreateError(result); return LogOnCreateError(result);
} }
result = client_->get_SecuredSettings(secured_settings.GetAddressOf()); result = client_->get_SecuredSettings(&secured_settings);
if (FAILED(result)) if (FAILED(result))
return LogOnCreateError(result); return LogOnCreateError(result);
...@@ -467,7 +467,7 @@ HRESULT RdpClientWindow::OnDisconnected(long reason) { ...@@ -467,7 +467,7 @@ HRESULT RdpClientWindow::OnDisconnected(long reason) {
// Get the error message as well. // Get the error message as well.
base::win::ScopedBstr error_message; base::win::ScopedBstr error_message;
Microsoft::WRL::ComPtr<mstsc::IMsRdpClient5> client5; Microsoft::WRL::ComPtr<mstsc::IMsRdpClient5> client5;
result = client_.CopyTo(client5.GetAddressOf()); result = client_.As(&client5);
if (SUCCEEDED(result)) { if (SUCCEEDED(result)) {
result = client5->GetErrorDescription(reason, extended_code, result = client5->GetErrorDescription(reason, extended_code,
error_message.Receive()); error_message.Receive());
......
...@@ -389,15 +389,15 @@ Microsoft::WRL::ComPtr<ISensor> PlatformSensorReaderWin32::GetSensorForType( ...@@ -389,15 +389,15 @@ Microsoft::WRL::ComPtr<ISensor> PlatformSensorReaderWin32::GetSensorForType(
Microsoft::WRL::ComPtr<ISensorManager> sensor_manager) { Microsoft::WRL::ComPtr<ISensorManager> sensor_manager) {
Microsoft::WRL::ComPtr<ISensor> sensor; Microsoft::WRL::ComPtr<ISensor> sensor;
Microsoft::WRL::ComPtr<ISensorCollection> sensor_collection; Microsoft::WRL::ComPtr<ISensorCollection> sensor_collection;
HRESULT hr = sensor_manager->GetSensorsByType( HRESULT hr =
sensor_type, sensor_collection.GetAddressOf()); sensor_manager->GetSensorsByType(sensor_type, &sensor_collection);
if (FAILED(hr) || !sensor_collection) if (FAILED(hr) || !sensor_collection)
return sensor; return sensor;
ULONG count = 0; ULONG count = 0;
hr = sensor_collection->GetCount(&count); hr = sensor_collection->GetCount(&count);
if (SUCCEEDED(hr) && count > 0) if (SUCCEEDED(hr) && count > 0)
sensor_collection->GetAt(0, sensor.GetAddressOf()); sensor_collection->GetAt(0, &sensor);
return sensor; return sensor;
} }
...@@ -484,7 +484,7 @@ bool PlatformSensorReaderWin32::SetReportingInterval( ...@@ -484,7 +484,7 @@ bool PlatformSensorReaderWin32::SetReportingInterval(
return false; return false;
Microsoft::WRL::ComPtr<IPortableDeviceValues> return_props; Microsoft::WRL::ComPtr<IPortableDeviceValues> return_props;
hr = sensor_->SetProperties(props.Get(), return_props.GetAddressOf()); hr = sensor_->SetProperties(props.Get(), &return_props);
return SUCCEEDED(hr); 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