0

I'm having some trouble with memory corruption in a rather large project to control some scientific hardware (ca. 6000 lines), and I'm not sure which is the best way/tool to solve the problem. The project uses Qt 4.8, and it's built with QtCreator and MinGW. The program works more or less, but I'm having some stability issues. Sometimes I get random crashes, but on some occasions, when I change the source code a little bit, the program will crash at exactly the same position (one which has worked previously). The position which it has picked this time looks like this:

 char stages2[1024];
 sprintf(stages2, "M-511.DD.LOAD\nNOSTAGE");

The second line gives a segmentation fault (SIGSEGV) when I run it in gdb - which tells me that I have some kind of problem with the program's memory, because I'm certain these two lines are correct. Also, the "crash site" changes depending on the exact source code; I've even seen crashes in Windows DLLs which Qt is using.

I've looked into a few options to find the cause of the problem, but I've run into some difficulties:

  • I've downloaded DUMA, but I just can't get it to compile on MinGW - I've had to change an include command in order to make the library, but now one of the test programs is failing. (Any hints or links to binaries, anyone?)
  • I've also tried Application Verifier, but when I run it it always stops at the same position, where a 3rd party DLL I'm using is leaking a handle. I'm reasonably sure this is not the cause of my problems, but I can't continue the debugging process because gdb always goes back to the same position (it only gets stuck there when I'm using Application verifier).
  • Finally, I've run my program with Dr. Memory, but it just crashes before reaching the main window, without giving me any useful outputs (the only thing I'm seeing is where Qt is apparently wasting some memory).

I'd be really grateful for some advice on what's the most promising method to finally get rid of this error.

xqrp
  • 137
  • 13

1 Answers1

-1

Compile with optimization and -Wall (and perhaps other warning flags), check all warnings to make sure nothing fishy is going on.

Use tools like valgrind to check for memory management snafus.

vonbrand
  • 11,412
  • 8
  • 32
  • 52
  • I think `-Wall` is on by default when you build in the debug configuration, but I'll check anyway. I'm stuck with Windows because of some third party stuff, so I guess I can't use valgrind - would you have any suggestions for Windows based tools? – xqrp Mar 10 '14 at 22:12
  • You can use [cppcheck](https://en.wikipedia.org/wiki/Cppcheck) to identify errors and smelly things. – ManuelAtWork May 31 '16 at 14:02
  • MinGW works on Windows, and Valgrind works on GNU/Linux. So the advice is not very helpful. However, a Qt programme should be portable to GNU/Linux with a little work.You can then try to use Valgrind. – user1741137 Jun 21 '20 at 10:04