MSVC & MinGW



  • Hello everyone,

    I recently spend an ungodly amount of time searching for an memory access violation error that only accured when compiled with MSVC2015.

    Turns out I forgot to set a Pointer back to NULL after deleting the object ... Silly me.

    Somehow this was not a problem with MinGW. Does the MinGW compiler automatically set the Pointer to NULL if you call deleteLater()? That would explain a lot.



  • No. Such behavior would violate C++ standard and cannot be expected from any reasonable compiler.

    What you are probably seeing is use-after-free, which in case of MinGW somehow works because old memory hasn't been overwritten yet, and in case of MSVC it gets overwritten fast enough to reveal the bug



  • Thanks for the clarification!
    That is actually more in line with my original reasoning: "This is just happenstance." ;-)

    I'll mark it as sloved, thanks again.


  • Moderators

    @J.Hilk said in MSVC & MinGW:

    I recently spend an ungodly amount of time searching for an memory access violation error

    A debugger would have found the source of the error fairly quickly.

    • For MinGW, use GDB (already included in the copy of MinGW that's bundled with Qt).
    • For MSVC, use CDB (installed separately)

    If you're working on a *nix machine, Valgrind is a tool designed specifically to detect memory errors like this.



  • @JKSH
    I actually used a debugger, the problem was, my program was halted not on the right spot but at random places in my code.
    I halted on *List.clear() .List is a list of pointers and List itself is a class, member and allocated on the stack. So I checked everything that was connected to the list and the objects it pointed to.
    The error itself that I later fixed was 10-20 lines above this entry...


  • Moderators

    @J.Hilk said in MSVC & MinGW:

    @JKSH
    I actually used a debugger, the problem was, my program was halted not on the right spot but at random places in my code.
    I halted on *List.clear() .List is a list of pointers and List itself is a class, member and allocated on the stack. So I checked everything that was connected to the list and the objects it pointed to.
    The error itself that I later fixed was 10-20 lines above this entry...

    Then a memory checker is our friend.

    I mentioned Valgrind in my previous post. It's not available on Windows, but Dr. Memory looks promising: http://www.drmemory.org/ (I haven't used this myself, though)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.