Reputation: 26477
I've got a console program that uses some of Qt classes. The following code is its fragment
std::cout << "before the problem (PVM constructor)" << std::endl;
image = new QImage(filename);
std::cout << "after the problem (PVM constructor)" << std::endl;
running it against valgrind throws some errors:
before the problem (PVM constructor)
==8344== Conditional jump or move depends on uninitialised value(s)
==8344== at 0x51D6D19: inflateReset2 (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
==8344== by 0x51D6E0C: inflateInit2_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
==8344== by 0x51D6E92: inflateInit_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
==8344== by 0x51B3F60: png_create_read_struct_2 (in /lib/i386-linux-gnu/libpng12.so.0.46.0)
==8344== by 0x42807AC: QImageReader::read(QImage*) (in /usr/lib/i386-linux-gnu/libQtGui.so.4.7.4)
==8344== by 0x4021BAF: ???
==8344== Uninitialised value was created by a heap allocation
==8344== at 0x4028876: malloc (vg_replace_malloc.c:236)
==8344== by 0x51C0796: png_malloc_default (in /lib/i386-linux-gnu/libpng12.so.0.46.0)
==8344== by 0x51C082C: png_malloc (in /lib/i386-linux-gnu/libpng12.so.0.46.0)
==8344== by 0x51A6A48: ??? (in /lib/i386-linux-gnu/libpng12.so.0.46.0)
==8344== by 0x51D6DE8: inflateInit2_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
==8344== by 0x51D6E92: inflateInit_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
==8344== by 0x51B3F60: png_create_read_struct_2 (in /lib/i386-linux-gnu/libpng12.so.0.46.0)
==8344== by 0x42807AC: QImageReader::read(QImage*) (in /usr/lib/i386-linux-gnu/libQtGui.so.4.7.4)
==8344== by 0x4021BAF: ???
==8344==
after the problem (PVM constructor)
Can you please help me to find what is the cause of the problem? Could it be that internal Qt libs have some dangerous constructions - or is it a matter of using Qt GUI lib inside a console program (don't think so but who knows)?
Upvotes: 0
Views: 337
Reputation: 2479
Valgrind will tell you if it finds memory leaks, like when you allocate memory on the heap but you never free it. I guess you just dont call delete image
after your program is done with it. That is something valgrind will pick up as a memory leak. It has nothing to do with Qt. The rule in C++ is: For every new there is 1 delete.
Upvotes: 3