Commit 99dbe47a authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

components: 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)).

Bug: 914910
Change-Id: I9bec0dbdc7e22519e7e5a31d93ef31ca9a654265
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2271522Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784491}
parent feb634e9
......@@ -20,7 +20,7 @@ bool IsNetworkBehindCaptivePortal(INetwork* network) {
return false;
Microsoft::WRL::ComPtr<IPropertyBag> property_bag;
if (FAILED(network->QueryInterface(property_bag.GetAddressOf())) ||
if (FAILED(network->QueryInterface(IID_PPV_ARGS(&property_bag))) ||
!property_bag) {
return false;
}
......@@ -71,7 +71,7 @@ bool IsBehindCaptivePortal() {
Microsoft::WRL::ComPtr<IEnumNetworks> enum_networks;
if (FAILED(network_list_manager->GetNetworks(NLM_ENUM_NETWORK_CONNECTED,
enum_networks.GetAddressOf()))) {
&enum_networks))) {
return false;
}
......@@ -87,7 +87,7 @@ bool IsBehindCaptivePortal() {
// says items_returned is set to NULL if the first parameter is 1, but this
// seems incorrect. In this call, items_returned is 1 until there are no
// networks. Then it becomes zero.
if (FAILED(enum_networks->Next(1, network.GetAddressOf(), &items_returned)))
if (FAILED(enum_networks->Next(1, &network, &items_returned)))
return false;
if (items_returned == 0)
......
......@@ -215,14 +215,14 @@ bool GetObjectUniqueId(IPortableDevice* device,
DCHECK(device);
DCHECK(unique_id);
Microsoft::WRL::ComPtr<IPortableDeviceContent> content;
HRESULT hr = device->Content(content.GetAddressOf());
HRESULT hr = device->Content(&content);
if (FAILED(hr)) {
DPLOG(ERROR) << "Failed to get IPortableDeviceContent interface";
return false;
}
Microsoft::WRL::ComPtr<IPortableDeviceProperties> properties;
hr = content->Properties(properties.GetAddressOf());
hr = content->Properties(&properties);
if (FAILED(hr)) {
DPLOG(ERROR) << "Failed to get IPortableDeviceProperties interface";
return false;
......@@ -234,7 +234,7 @@ bool GetObjectUniqueId(IPortableDevice* device,
Microsoft::WRL::ComPtr<IPortableDeviceValues> properties_values;
if (FAILED(properties->GetValues(object_id.c_str(), properties_to_read.Get(),
properties_values.GetAddressOf()))) {
&properties_values))) {
return false;
}
......@@ -265,7 +265,7 @@ bool GetRemovableStorageObjectIds(
DCHECK(device);
DCHECK(storage_object_ids);
Microsoft::WRL::ComPtr<IPortableDeviceCapabilities> capabilities;
HRESULT hr = device->Capabilities(capabilities.GetAddressOf());
HRESULT hr = device->Capabilities(&capabilities);
if (FAILED(hr)) {
DPLOG(ERROR) << "Failed to get IPortableDeviceCapabilities interface";
return false;
......@@ -273,7 +273,7 @@ bool GetRemovableStorageObjectIds(
Microsoft::WRL::ComPtr<IPortableDevicePropVariantCollection> storage_ids;
hr = capabilities->GetFunctionalObjects(WPD_FUNCTIONAL_CATEGORY_STORAGE,
storage_ids.GetAddressOf());
&storage_ids);
if (FAILED(hr)) {
DPLOG(ERROR) << "Failed to get IPortableDevicePropVariantCollection";
return false;
......
......@@ -178,7 +178,7 @@ int GetHttpStatusFromBitsError(HRESULT error) {
HRESULT GetFilesInJob(const ComPtr<IBackgroundCopyJob>& job,
std::vector<ComPtr<IBackgroundCopyFile>>* files) {
ComPtr<IEnumBackgroundCopyFiles> enum_files;
HRESULT hr = job->EnumFiles(enum_files.GetAddressOf());
HRESULT hr = job->EnumFiles(&enum_files);
if (FAILED(hr))
return hr;
......@@ -189,7 +189,7 @@ HRESULT GetFilesInJob(const ComPtr<IBackgroundCopyJob>& job,
for (ULONG i = 0; i != num_files; ++i) {
ComPtr<IBackgroundCopyFile> file;
if (enum_files->Next(1, file.GetAddressOf(), nullptr) == S_OK && file.Get())
if (enum_files->Next(1, &file, nullptr) == S_OK && file.Get())
files->push_back(file);
}
......@@ -280,7 +280,7 @@ HRESULT GetJobError(const ComPtr<IBackgroundCopyJob>& job,
HRESULT* error_code_out) {
*error_code_out = S_OK;
ComPtr<IBackgroundCopyError> copy_error;
HRESULT hr = job->GetError(copy_error.GetAddressOf());
HRESULT hr = job->GetError(&copy_error);
if (FAILED(hr))
return hr;
......@@ -302,7 +302,7 @@ HRESULT FindBitsJobIf(Predicate pred,
const ComPtr<IBackgroundCopyManager>& bits_manager,
std::vector<ComPtr<IBackgroundCopyJob>>* jobs) {
ComPtr<IEnumBackgroundCopyJobs> enum_jobs;
HRESULT hr = bits_manager->EnumJobs(0, enum_jobs.GetAddressOf());
HRESULT hr = bits_manager->EnumJobs(0, &enum_jobs);
if (FAILED(hr))
return hr;
......@@ -315,7 +315,7 @@ HRESULT FindBitsJobIf(Predicate pred,
// the job description matches the component updater jobs.
for (ULONG i = 0; i != job_count; ++i) {
ComPtr<IBackgroundCopyJob> current_job;
if (enum_jobs->Next(1, current_job.GetAddressOf(), nullptr) == S_OK &&
if (enum_jobs->Next(1, &current_job, nullptr) == S_OK &&
pred(current_job)) {
base::string16 job_name;
hr = GetJobDisplayName(current_job, &job_name);
......@@ -727,7 +727,7 @@ HRESULT BackgroundDownloader::CreateOrOpenJob(const GURL& url,
GUID guid = {0};
hr = bits_manager_->CreateJob(kJobName, BG_JOB_TYPE_DOWNLOAD, &guid,
local_job.GetAddressOf());
&local_job);
if (FAILED(hr)) {
CleanupJob(local_job);
return hr;
......@@ -825,12 +825,11 @@ HRESULT BackgroundDownloader::UpdateInterfacePointers() {
return hr;
hr = GetInterfaceFromGit(git, git_cookie_bits_manager_,
IID_PPV_ARGS(bits_manager_.GetAddressOf()));
IID_PPV_ARGS(&bits_manager_));
if (FAILED(hr))
return hr;
hr = GetInterfaceFromGit(git, git_cookie_job_,
IID_PPV_ARGS(job_.GetAddressOf()));
hr = GetInterfaceFromGit(git, git_cookie_job_, IID_PPV_ARGS(&job_));
if (FAILED(hr))
return 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