On 11/25/2013 12:43 PM, Slava wrote:
I guess, you cannot pass temporaries into TeeDevice constructor and have to hold dummyFileHandle and logStream2 alive as long as they are referenced in TeeDevice (making them class members accessed through shared_ptr perhaps?).
Indeed, that was also my first conclusion but if I explicitly create temporary sinks by scoping but then flush and close the stream in the same constructor all works fine and Valgrind reports no issues: { std::ofstream dummyFileHandle("/dev/null", std::ios_base::out | std::ios_base::app); std::stringstream logStream2; TeeDevice myTee (logStream2, dummyFileHandle); m_out.open(myTee); } if(m_out.is_open()) { m_out.flush(); m_out.close(); } In fact, my earlier code also works fine if you do not pass the unused logStream to the constructor, which I find very confusing...