Skip to content

Commit

Permalink
arc: Fix the string_view dangling pointer issue
Browse files Browse the repository at this point in the history
This CL create a new string when binding callback.

BUG=b:310260986
TEST=ArcAppLaunchThrottleObserverTest

Change-Id: I69074b817323b28baf1648e7296296a5a853bc77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5019669
Commit-Queue: Shengsong Tan <[email protected]>
Reviewed-by: Yuichiro Hanada <[email protected]>
Reviewed-by: Alexandre Marciano Gimenez <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1224042}
  • Loading branch information
sstanGPT authored and Chromium LUCI CQ committed Nov 14, 2023
1 parent f9ce056 commit a50d8f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void ArcAppLaunchThrottleObserver::OnWillDestroyWatcher() {
}

void ArcAppLaunchThrottleObserver::OnLaunchedOrRequestExpired(
const std::string& name) {
const std::string name) {
// This request has already expired or there are outstanding requests,
// do not deactivate the observer.
if (!current_requests_.erase(name) || current_requests_.size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ArcAppLaunchThrottleObserver
void OnWillDestroyWatcher() override;

private:
void OnLaunchedOrRequestExpired(const std::string& name);
void OnLaunchedOrRequestExpired(const std::string name);

std::set<std::string> current_requests_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,14 @@ TEST_F(ArcAppLaunchThrottleObserverTest, TestWindowWatcherEffectOnInit) {
}
}

TEST_F(ArcAppLaunchThrottleObserverTest, TestCallbackString) {
auto temp_id = std::make_unique<std::string>("test_app_id");
observer()->OnArcAppLaunchRequested(*temp_id);
temp_id.reset();

// Expect no crash & memory leak.
environment()->FastForwardUntilNoTasksRemain();
}

} // namespace
} // namespace arc

0 comments on commit a50d8f6

Please sign in to comment.