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

Fixes crash for null ptr #4263

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1187,9 +1187,16 @@ void RewardsServiceImpl::LoadNicewareList(
void RewardsServiceImpl::SavePublisherInfo(
ledger::PublisherInfoPtr publisher_info,
ledger::PublisherInfoCallback callback) {
DCHECK(publisher_info);
if (!publisher_info) {
NejcZdovc marked this conversation as resolved.
Show resolved Hide resolved
callback(ledger::Result::LEDGER_ERROR, std::move(publisher_info));
return;
}

auto copy = publisher_info->Clone();
base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
base::BindOnce(&SavePublisherInfoOnFileTaskRunner,
publisher_info->Clone(),
std::move(copy),
Copy link
Collaborator

@tmancey tmancey Dec 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a developer is copy/pasting there is potential for a bug, a safer approach would be to clone publisher_info inline for each std::bind. However, as we all know, copy/paste is the root of all evil

Copy link
Contributor Author

@NejcZdovc NejcZdovc Dec 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the main problem, why we saw crashes. If checks are just additional safety measurements

publisher_info_backend_.get()),
base::BindOnce(&RewardsServiceImpl::OnPublisherInfoSaved,
AsWeakPtr(),
Expand All @@ -1210,6 +1217,12 @@ void RewardsServiceImpl::OnPublisherInfoSaved(
void RewardsServiceImpl::SaveActivityInfo(
ledger::PublisherInfoPtr publisher_info,
ledger::PublisherInfoCallback callback) {
DCHECK(publisher_info);
if (!publisher_info) {
callback(ledger::Result::LEDGER_ERROR, std::move(publisher_info));
return;
}

ledger::PublisherInfoPtr copy = publisher_info->Clone();
base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
base::BindOnce(&SaveActivityInfoOnFileTaskRunner,
Expand Down