Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc

Issue 426303002: Fix race condition in CpuInfoProvider::QueryCpuTimePerProcessor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modify comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
diff --git a/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc b/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
index 8caecc29322d557ff7ea9c90d0b3efb549286f30..788541408074b220c6118945332b3bcd7afe2db3 100644
--- a/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
+++ b/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
@@ -37,20 +37,34 @@ bool CpuInfoProvider::QueryCpuTimePerProcessor(
if (line.compare(0, 3, "cpu") != 0)
continue;
+ // The number of entries in /proc/stat may mismatch the size of infos
+ // because the number of online processors may change after the value has
+ // been decided in CpuInfoProvider::QueryInfo().
+ //
+ // TODO(jchuang): fix the fail case by using the number of configured
+ // processors instead of online processors.
+ if (i == infos->size()) {
+ LOG(ERROR) << "Got more entries in /proc/stat than online CPUs";
+ return false;
+ }
+
uint64 user = 0, nice = 0, sys = 0, idle = 0;
int vals = sscanf(line.c_str(),
"%*s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64,
&user, &nice, &sys, &idle);
DCHECK_EQ(4, vals);
- DCHECK(i < infos->size());
infos->at(i)->usage.kernel = static_cast<double>(sys);
infos->at(i)->usage.user = static_cast<double>(user + nice);
infos->at(i)->usage.idle = static_cast<double>(idle);
infos->at(i)->usage.total = static_cast<double>(sys + user + nice + idle);
++i;
}
- DCHECK_EQ(infos->size(), i);
+ if (i < infos->size()) {
+ LOG(ERROR) << "Got fewer entries in /proc/stat than online CPUs";
+ return false;
+ }
+
return true;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698