acimpoeru / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Possible Race condition at logging.cc:1012 google::RawLog__SetLastTime #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. run a multithreaded program that uses google-glog with valgrind 
--tool=helgrind

What is the expected output? What do you see instead?
I expect zero error reports from valgrind and I get a lot of errors.

What version of the product are you using? On what operating system?
 google-glog 0.3.1
 valgrind 3.5.0
 g++ 4.1.2 20080704 (Red Hat 4.1.2-48)
 CentOS 5.2

Please provide any additional information below.

This is the output of valgrind:

==12505==    at 0x403B4DE: google::RawLog__SetLastTime(tm const&, int) 
(raw_logging.cc:78)
==12505==    by 0x403411A: google::LogMessage::Init(char const*, int, int, void 
(google::LogMessage::*)()) (logging.cc:1012)
==12505==    by 0x4034B12: google::LogMessage::LogMessage(char const*, int) 
(logging.cc:944)

google::RawLog__SetLastTime calls memcpy on a static variable and there is not 
lock around it to protect it from concurrent accesses.

Modifying logging.cc at line 1012 like below may fix this problem:

{
  MutexLock l(&log_mutex);
  RawLog__SetLastTime(data_->tm_time_, usecs);
}

or if this is not really a race condition let me know so I can create a 
valgrind suppression rule.

Original issue reported on code.google.com by Horacio....@gmail.com on 31 Aug 2010 at 3:29

GoogleCodeExporter commented 8 years ago
this looks clearly a race condition, although it looks like a low risk one.

Original comment by Dian....@gmail.com on 15 Dec 2011 at 12:20

GoogleCodeExporter commented 8 years ago
Same report from clang thread sanitizer

Original comment by mend...@gmail.com on 29 Sep 2014 at 9:51