
Hi, When I run the following program it runs successfully but throws an exception during shutdown. I don't know why, but it seems that the call to boost::filesystem::file_size() is corrupting memory somehow. This example only shows the call to file_size() but I think I've seen similar trouble with other calls within boost::filesystem. Am I doing something wrong here or is this a bug? Regards, Jason Aubrey ---------------------- Environment: OS: Win2k Compiler: VS7.1 Boost: v1.33.1 ---------------------- #include <boost/filesystem/operations.hpp> #include <fstream> int main(int, char**) { // Create a file using namespace std; const string fileName("/temp/test.txt"); ofstream file; file.open(fileName.c_str()); const string message("this is a test"); file << message; file.close(); const boost::intmax_t fileSize = boost::filesystem::file_size(fileName); if( fileSize != message.size() ) throw std::exception("Bad result"); return 0; } ---------------------- The following pop-up occurs during program completion: Window Title="Microsoft Visual C++ Debug Library" Window Icon=Critical Error Window Text=" Debug Assertion Failed! Program: .... File: dbgdel.cpp Line: 52 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application)" Buttons=[Abort] [Retry] [Ignore]

Aubrey, Jason wrote:
Hi,
When I run the following program it runs successfully but throws an exception during shutdown. I don't know why, but it seems that the call to boost::filesystem::file_size() is corrupting memory somehow. This example only shows the call to file_size() but I think I've seen similar trouble with other calls within boost::filesystem.
Am I doing something wrong here or is this a bug?
Regards, Jason Aubrey
----------------------
Environment: OS: Win2k Compiler: VS7.1 Boost: v1.33.1
----------------------
#include <boost/filesystem/operations.hpp> #include <fstream>
int main(int, char**) { // Create a file using namespace std; const string fileName("/temp/test.txt"); ofstream file; file.open(fileName.c_str()); const string message("this is a test"); file << message; file.close();
const boost::intmax_t fileSize = boost::filesystem::file_size(fileName);
if( fileSize != message.size() ) throw std::exception("Bad result");
return 0; }
Either I'm missing something, or... file_size takes a path reference as its calling argument. You're passing a string. How does this even compile? - Rush

Replies are at the end of this message: Aubrey, Jason wrote:
Hi,
When I run the following program it runs successfully but throws an exception during shutdown. I don't know why, but it seems that the call to boost::filesystem::file_size() is corrupting memory somehow. This example only shows the call to file_size() but I think I've seen similar trouble with other calls within boost::filesystem.
Am I doing something wrong here or is this a bug?
Regards, Jason Aubrey
----------------------
Environment: OS: Win2k Compiler: VS7.1 Boost: v1.33.1
----------------------
#include <boost/filesystem/operations.hpp> #include <fstream>
int main(int, char**) { // Create a file using namespace std; const string fileName("/temp/test.txt"); ofstream file; file.open(fileName.c_str()); const string message("this is a test"); file << message; file.close();
const boost::intmax_t fileSize = boost::filesystem::file_size(fileName);
if( fileSize != message.size() ) throw std::exception("Bad result");
return 0; }
Either I'm missing something, or... file_size takes a path reference as its calling argument. You're passing a string. How does this even compile? - Rush _______________________________________________ Thanks for the Reply Rush. If I modify the above code to contain the following I still see the same behavior: const boost::filesystem::path filePath(fileName); const boost::intmax_t fileSize = boost::filesystem::file_size(filePath); Regards, Jason Aubrey

Aubrey, Jason wrote:
Hi,
When I run the following program it runs successfully but throws an exception during shutdown. I don't know why, but it seems that the call to boost::filesystem::file_size() is corrupting memory somehow. This example only shows the call to file_size() but I think I've seen similar trouble with other calls within boost::filesystem.
Am I doing something wrong here or is this a bug?
Regards, Jason Aubrey
Jason, When something like this happens, I have a function that checks all of the heap for corruption errors. If you place enough calls to this function, you can use it to find where the corruption happens. David #include <malloc.h> #include <stdlib.h> // HeapCheckWin32() // ---------------- // Sends an output to the TRACE() function with the // status of the heap. (Actually, it seems to hit // an assert inside of _heapwalk when there is an error.) // Returns 0 for ok, non-zero for error. int HeapCheckWin32() { _HEAPINFO hinfo; int heapstatus; int retStatus = 1; // start with error status hinfo._pentry = NULL; do { heapstatus = _heapwalk(&hinfo); } while(heapstatus == _HEAPOK); switch(heapstatus) { case _HEAPEMPTY: TRACE("OK - empty heap\n"); retStatus = 0; break; case _HEAPEND: TRACE("OK - end of heap\n"); retStatus = 0; break; case _HEAPBADPTR: TRACE("ERROR - bad pointer to heap\n"); retStatus = 1; break; case _HEAPBADBEGIN: TRACE("ERROR - bad start of heap\n"); retStatus = 1; break; case _HEAPBADNODE: TRACE("ERROR - bad node in heap\n"); retStatus = 1; break; default: retStatus = 2; break; } return retStatus; }

Thanks David. I'll probably be tied up on other issues for 1-3 days but I will give this a try when I can. Regards, Jason -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of David Walthall Sent: Wednesday, November 01, 2006 11:03 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost filesystem Aubrey, Jason wrote:
Hi,
When I run the following program it runs successfully but throws an exception during shutdown. I don't know why, but it seems that the call to boost::filesystem::file_size() is corrupting memory somehow. This example only shows the call to file_size() but I think I've seen similar trouble with other calls within boost::filesystem.
Am I doing something wrong here or is this a bug?
Regards, Jason Aubrey
Jason, When something like this happens, I have a function that checks all of the heap for corruption errors. If you place enough calls to this function, you can use it to find where the corruption happens. David #include <malloc.h> #include <stdlib.h> // HeapCheckWin32() // ---------------- // Sends an output to the TRACE() function with the // status of the heap. (Actually, it seems to hit // an assert inside of _heapwalk when there is an error.) // Returns 0 for ok, non-zero for error. int HeapCheckWin32() { _HEAPINFO hinfo; int heapstatus; int retStatus = 1; // start with error status hinfo._pentry = NULL; do { heapstatus = _heapwalk(&hinfo); } while(heapstatus == _HEAPOK); switch(heapstatus) { case _HEAPEMPTY: TRACE("OK - empty heap\n"); retStatus = 0; break; case _HEAPEND: TRACE("OK - end of heap\n"); retStatus = 0; break; case _HEAPBADPTR: TRACE("ERROR - bad pointer to heap\n"); retStatus = 1; break; case _HEAPBADBEGIN: TRACE("ERROR - bad start of heap\n"); retStatus = 1; break; case _HEAPBADNODE: TRACE("ERROR - bad node in heap\n"); retStatus = 1; break; default: retStatus = 2; break; } return retStatus; } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Aubrey, Jason
-
David Walthall
-
Rush Manbert