PDA

View Full Version : QFile::open throws std::bad_alloc for no obvious reason



nateriver
28th December 2009, 17:42
Constructing QFile object:

QFile file("file.ext");
"file.ext" is present in working directory. Calling file.open(QFile::ReadOnly | QFile::Text) terminates application with error:

terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
The same happens if I try to open embedded resource file.
It can't be the lack of memory because I have 2 of 4 GB of RAM free, neither the lack of available file handles to acquire, since Windows imposes no limitations on this.
Any help would be greatly appreciated.

P.S. The code that tries to open the file is loaded and executed from shared library, but I highly doubt that it can be the case.
P.P.S. Qt 4.6, Windows XP SP3

squidge
28th December 2009, 18:06
If you are running 32-bit Windows, then memory MIGHT be an issue, as even if you have 64GB of RAM, each application only has access to 2GB.

But I suspect that this is something more difficult to track down, such as memory corruption. Maybe you are corrupting the heap?

nateriver
29th December 2009, 06:42
Still I doubt that it's memory because I've just started developing this application, it only allocates about 100 kb (I'm not taking overhead into account).
For the same reason it's not likely to be heap corruption, since memory management is very simple in my app thus failproof.

The only thing that comes in my mind is that it's a bug in Qt, since I've actually seen people with similar problem on several forums.

nateriver
29th December 2009, 07:10
Khm, sorry, the exception was not caused by QFile::open but by some hacky code I wrote myself, so the problem is solved.