0

I've been migrating a project on Solaris from compat mode (4) to 64-bit with STL and the standard streams library.

For the most part, I've managed to overcome quite a lot of issues. I am however running into some issues surrounding streams and destruction.

---- called from signal handler with signal 10 (SIGBUS) ------
[7] realfree(0x108be78e8, 0x5554d45f54d7d4d7, 0x1da530, 0x5554d45f54d7d4d4, 0xffffffff7ae3e000, 0x108be78d8), at 0xffffffff7ac63b2c
[8] cleanfree(0x0, 0x1d9bc4, 0xffffffff7ae4ead8, 0xffffffff7accfcec, 0xffffffff7ae3e000, 0xffffffff7ae4ebd8), at 0xffffffff7ac64498
[9] _malloc_unlocked(0x20, 0x0, 0x0, 0xffffffff7ae3e000, 0x0, 0x0), at 0xffffffff7ac634f4
[10] malloc(0x20, 0x23e0, 0x1dac88, 0xffffffff7ac633d8, 0xffffffff7ae3e000, 0x2000), at 0xffffffff7ac633c8
[11] operator new(0x20, 0x0, 0x1, 0x1068d4, 0x105584e70, 0xffffffff7b20f028), at 0xffffffff7b108770
[12] std::basic_filebuf<char,std::char_traits<char> >::close(0x108bf7a60, 0x108bfbd30, 0xffffffffffffffff, 0xffffffff7ae4c060, 0xffffffffffffffe0, 0x108bf7a60), at 0xffffffff7b37657c
[13] std::basic_filebuf<char,std::char_traits<char> >::~basic_filebuf(0x108bf7a60, 0x108bfbe38, 0x0, 0x0, 0x0, 0x0), at 0xffffffff7b3764c4
[14] std::basic_ifstream<char,std::char_traits<char> >::~basic_ifstream(0x108bf7a48, 0x1c8, 0x24, 0x1021a66d0, 0x1af984, 0x0), at 0xffffffff7b3f30d4 

I came across some funky issues around std streams with setbuf() and the size of the buffer and thought that was the main issue, but the issue appears to resurfaced.

Has anyone else had similar experience around migrating C++ code from compat to std 64 and could offer any insight as to how to fix SIGBUS's around streams?

Brad Mitchell
  • 254
  • 1
  • 3
  • 12

1 Answers1

1

In case anyone is wondering, it appears that Standard C++ streams on Solaris (RWTools 7), the destructor for fstream etc will delete the buffer you set with pubsetbuf.

Which means doing stuff like:

char buf[1024];
ofstream out;
out.rdbuf()->pubsetbuf(buf, 1024);

is not good. It will actually delete your memory declared on the stack. I've tested a simple application which news a char* buffer and sets the buffer using setbuf/pubsetbuf for compat mode (4) and version (5) with the standard IO Streams library.

In compat mode, there are memory leaks, as the char* is not deleted. In the case of the standard io stream library, there are no memory leaks.

Similarly, if you delete the pointer, you'll get a duf with dbx access checking and baf if you have a char array declared on the stack.

Pretty much means, I have a lot of code to change :(

Brad Mitchell
  • 254
  • 1
  • 3
  • 12