This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug/Memory Leak in <strstream>


> While purifying one of my programs I found a leak in <strstream>.

Thanks for your bug report. This is not a bug in gcc, but in your
code. A strstream object freezes its contents when you perform
.str(). So you either need to release the result of .str() yourself,
or you need to unfreeze the stream:

#include <strstream>

int main()
{
  int i;
  std::ostrstream OS;
  OS << "123" << '\0';
  std::istrstream IS(OS.str());
  IS >> i;
  std::cout << i << std::endl;
  OS.freeze(0);
  return 0;
}

Hope this helps,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]