Boost logo

Boost Users :

Subject: Re: [Boost-users] [Iostreams] Segmentation fault when stream is flushed or closed
From: Steven Maenhout (Steven.Maenhout_at_[hidden])
Date: 2013-11-25 07:21:33


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...


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net