|
From: 邓尧 <to...@gm...> - 2013-03-21 04:25:05
|
Hi,
I'm running into a very weird valgrind behavior, not sure whether it's a
bug in my code or bug in valgrind.
The following is source code that runs well:
void ServerPool::processConnection(int connection) {
int offset = getWorker();
Context& context = pool->getContext(offset);
int* fd = &context.pipe[1];
wrapper::write_(*fd, &connection, sizeof(connection));
lastWorker = offset;
}
Context is defined as:
struct Context {
ServerPool* volatile self;
int pipe[2];
Context();
virtual ~Context();
};
If the following two lines:
int* fd = &context.pipe[1];
wrapper::write_(*fd, &connection, sizeof(connection));
with
int fd = context.pipe[1];
wrapper::write_(fd, &connection, sizeof(connection));
the program will crash, I checked the coredump generated by valgrind, in
the value of variable "fd" is
-1. Both code would run correctly without valgrind.
I got this situation under both valgrind 3.7.0 and 3.8.1, ubuntu linux
12.04 64-bit. source code compiled with gcc 4.6.3, glibc version 2.15
BTW, wrapper::write_() is simple a wrapper function around the system call
write(), it checks the return value of write(), if the value is less than
expected, it will throw an exception. pool->getContext() simply returns a
reference to a new'ed instance.
Thanks
Yao
|