1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Seg Fault Mem Leak

Discussion in 'C++' started by mmoose68, Jun 23, 2009.

  1. mmoose68

    mmoose68 New Member

    Alright, I get your point. I stripped the program down to what you suggested and ran it with my large (60,000 lines) rawdata.txt file. The program is not segfaulting...

    This is strange because when reading from the COM port, it does segfault in much shorter time. Why could this be?
  2. xpi0t0s

    xpi0t0s Mentor

    Maybe what's coming in at the COM port differs from the text file? Perhaps you could try logging what is read at the com port into a text file and then look through it for differences from what you're expecting.
    If you write out to log immediately after the fgets then you can be reasonably sure of getting an accurate representation of what's coming in. Also unflushed data in buffers can be lost when the program crashes so make sure when logging you open the log file, write the data and close the log file - it'll slow the program down a bit but you'll be certain to see what comes in at the time the crash occurs.
    Or if you don't have that much storage, write the data to screen but again make sure you flush the buffers to make sure that what is printed is displayed before the crash - I don't know how you do that with cout but if you use printf instead then fflush(stdout) will do the trick, i.e.
    - this way Hello is guaranteed to be printed when the crash occurs.
  3. mmoose68

    mmoose68 New Member

    Well... The problem seems to be very narrowed down. When I got rid of my cout and wrote with fprintf to a file, it did not segfault. I guess this points that it was overflowing the stdout buffer.

    Thanks for all the help!

Share This Page