ios: Ensure ScopedLockedFileHandle and UploadReportMac destructor order.

Followup to crrev.com/c/3573184, which did not honor destructor order,
leading to the background task releasing before the lock.

Bug: 1313555
Change-Id: Ifbd3902964552458b83cfc550f50058067021499
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3591012
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
This commit is contained in:
Justin Cohen 2022-04-18 13:59:02 -04:00 committed by Crashpad LUCI CQ
parent 36c88b15b7
commit 8647761c7d
3 changed files with 12 additions and 4 deletions

View File

@ -183,13 +183,14 @@ class CrashReportDatabaseMac : public CrashReportDatabase {
//! \brief A private extension of the Report class that maintains bookkeeping
//! information of the database.
struct UploadReportMac : public UploadReport {
#if BUILDFLAG(IS_IOS)
//! \brief Obtain a background task assertion while a flock is in use.
//! Ensure this is defined first so it is destroyed last.
internal::ScopedBackgroundTask ios_background_task{"UploadReportMac"};
#endif // BUILDFLAG(IS_IOS)
//! \brief Stores the flock of the file for the duration of
//! GetReportForUploading() and RecordUploadAttempt().
base::ScopedFD lock_fd;
#if BUILDFLAG(IS_IOS)
//! \brief Obtain a background task assertion while a flock is in use.
internal::ScopedBackgroundTask ios_background_task{"UploadReportMac"};
#endif // BUILDFLAG(IS_IOS)
};
//! \brief Locates a crash report in the database by UUID.

View File

@ -93,6 +93,11 @@ Settings::ScopedLockedFileHandle& Settings::ScopedLockedFileHandle::operator=(
return *this;
}
Settings::ScopedLockedFileHandle::~ScopedLockedFileHandle() {
// Call reset() to ensure the lock is released before the ios_background_task.
reset();
}
#endif // BUILDFLAG(IS_IOS)
namespace internal {

View File

@ -171,6 +171,8 @@ class Settings {
ScopedLockedFileHandle(ScopedLockedFileHandle&& rvalue);
ScopedLockedFileHandle& operator=(ScopedLockedFileHandle&& rvalue);
~ScopedLockedFileHandle();
private:
std::unique_ptr<internal::ScopedBackgroundTask> ios_background_task_;
};