Note that there are some explanatory texts on larger screens.

plurals
  1. POsegmentation fault appearing when program parameters are over a certain threshold
    primarykey
    data
    text
    <p>I'm writing this fairly big network simulator in C++. I've been regularly testing individual pieces as I was developing them, and after putting everything together it seems to work as long as the load I impose on the simulator is not too big (it's a P2P content distribution simulator, so the more different "contents" I introduce the more data transfers the simulator will have to handle). Anything above a certain threshold of the number of different contents being simulated will result in an abrupt SIGSEGV after several minutes of smooth running. I assumed there was a memory leak that was eventually becoming too large and messing things up, but a valgrind run with the parameters below the threshold terminated flawlessly. However, if I try to run the program with valgrind using a critical value for the content number, after a certain point I start to get memory access errors in functions that previously presented no problems:</p> <pre><code>==5987== Invalid read of size 8 ==5987== at 0x40524E: Scheduler::advanceClock() (Scheduler.cpp:38) ==5987== by 0x45BA73: TestRun::execute() (TestRun.cpp:73) ==5987== by 0x45522B: main (CDSim.cpp:131) ==5987== Address 0x2e63bc70 is 0 bytes inside a block of size 32 free'd ==5987== at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5987== by 0x405487: Scheduler::advanceClock() (Scheduler.cpp:69) ==5987== by 0x45BA73: TestRun::execute() (TestRun.cpp:73) ==5987== by 0x45522B: main (CDSim.cpp:131) ==5987== ==5987== Invalid read of size 4 ==5987== at 0x40584E: Request::getSimTime() const (Event.hpp:45) ==5987== by 0x40525C: Scheduler::advanceClock() (Scheduler.cpp:38) ==5987== by 0x45BA73: TestRun::execute() (TestRun.cpp:73) ==5987== by 0x45522B: main (CDSim.cpp:131) ==5987== Address 0x2e63bc78 is 8 bytes inside a block of size 32 free'd ==5987== at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5987== by 0x405487: Scheduler::advanceClock() (Scheduler.cpp:69) ==5987== by 0x45BA73: TestRun::execute() (TestRun.cpp:73) ==5987== by 0x45522B: main (CDSim.cpp:131) ==5987== </code></pre> <p>I know it might be hard to give an answer without seeing the whole code, but is there a "high-level" hint on what might be going on here? I don't understand why a function that seems to work normally suddenly starts misbehaving. Is there something obvious that I'm missing maybe?</p> <p>The incriminated line in the previous valgrind log is <code>if (nextEvent-&gt;getSimTime() &lt; this-&gt;getSimTime())</code> in the following block:</p> <pre><code>bool Scheduler::advanceClock() { if (pendingEvents.size() == 0) { std::cerr &lt;&lt; "WARNING: Scheduler::advanceClock() - Empty event queue before " "reaching the termination event" &lt;&lt; std::endl; return false; } const Event* nextEvent = pendingEvents.top(); // Check that the event is not scheduled in the past if (nextEvent-&gt;getSimTime() &lt; this-&gt;getSimTime()) { std::cerr &lt;&lt; "Scheduler::advanceClock() - Event scheduled in the past!" &lt;&lt; std::endl; std::cerr &lt;&lt; "Simulation time: " &lt;&lt; this-&gt;getSimTime() &lt;&lt; ", event time: " &lt;&lt; nextEvent-&gt;getSimTime() &lt;&lt; std::endl; exit(ERR_EVENT_IN_THE_PAST); } // Update the clock with the current event time (&gt;= previous time) this-&gt;setSimTime(nextEvent-&gt;getSimTime()); ... </code></pre> <p>where pendingEvents is a boost::heap::binomial_heap.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload