On Mon, May 13, 2013 at 6:46 AM, Gonzalo <[email protected]> wrote:

> ==8527== Process terminating with default action of signal 11 (SIGSEGV)
> ==8527==  Access not within mapped region at address 0xBEF3EDA4
> ==8527==    at 0x8091CD0: WriteFiasco(std::string const&) (fiasco_finder.h:28)
> ==8527==    by 0x43F810D: __static_initialization_and_destruction_0(int, int) 
> (exceptions.cpp:2)
> ==8527==    by 0x43F817D: global constructors keyed to exceptions.cpp 
> (exceptions.cpp:122)

...

> inline bool WriteFiasco(const std::string& fileName)
> {
>     static int counter = 0;
>     ++counter;
>
>     std::ofstream file;
>     file.open("FiascoFinder.txt", std::ios::out | std::ios::app);
>     file << "Starting to initialize file - number: [" << counter << "] 
> filename: [" << fileName.c_str() << "]" << std::endl;
>     file.flush();
>     file.close();
>     return true;                                  <----- line 28
> }

Looks like a crash in the std::ofstream destructor.  You will need to
disassemble your code near the fault (0x8091CD0) to be sure.

The order in which static global constructors run is unspecified in
C++. I do not know whether this order can be affected by running under
Valgrind, but if so, it could explain your failure. Perhaps some
global static object in the C++ runtime has to be constructed before
std::ofstream will work at all. (I am certain this can happen if you
use, say, std::cout; I am actually a little surprised to see it for
std::ofstream.)

Anyway, it is possible that if you change this code not to use
std::ofstream, and just use read()/write() or fread()/fwrite(), then
you will work around the problem.

Then again this could just be a problem with Valgrind. A disassembly
near the fault is the first step toward finding out.

 - Pat

P.S. As an aside, this is one reason most C++ experts recommend
avoiding global objects when possible and using the "Meyers Singleton"
when not.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to