Skip to content

Commit

Permalink
Fix random value of CachedReader at first time (apache#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright authored Mar 12, 2024
1 parent 17a200c commit 965279f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bvar/default_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static bool read_proc_status(ProcStat &stat) {
template <typename T>
class CachedReader {
public:
CachedReader() : _mtime_us(0) {
CachedReader() : _mtime_us(0), _cached{} {
CHECK_EQ(0, pthread_mutex_init(&_mutex, NULL));
}
~CachedReader() {
Expand All @@ -150,7 +150,7 @@ class CachedReader {
pthread_mutex_unlock(&p->_mutex);
// don't run fn inside lock otherwise a slow fn may
// block all concurrent bvar dumppers. (e.g. /vars)
T result;
T result{};
if (fn(&result)) {
pthread_mutex_lock(&p->_mutex);
p->_cached = result;
Expand Down

0 comments on commit 965279f

Please sign in to comment.