2013-06-28 65 views
3

我正在調試我的C++應用程序valgrind --leak-check=yes,我收到了很多關於可能的內存泄漏的信息。這是使用Qt,POSIX線程和QuantLib的C++應用程序。我認爲這些信息是不正確的,我已經測試過,並且我收到了很多這些信息,即使應用程序非常簡單,Qt應用程序也什麼都不做。可能valgrind會誤解有關Qt和POSIX線程的內存信息。如何檢查Linux上的C++ Qt應用程序中的內存泄漏?

我的問題是我該怎麼做,如何正確調試這個Qt應用程序,理想情況下使用valgrind,但如果可能可能採用不同的方式?

==9419== Memcheck, a memory error detector 
==9419== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. 
==9419== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info 
==9419== Command: ./qt_tradingclient_1 
==9419== Parent PID: 19797 
==9419== 
==9419== 
==9419== HEAP SUMMARY: 
==9419==  in use at exit: 1,587,688 bytes in 10,156 blocks 
==9419== total heap usage: 365,203 allocs, 355,047 frees, 92,510,461 bytes allocated 
==9419== 
==9419== 1 bytes in 1 blocks are possibly lost in loss record 3 of 5,210 
==9419== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 
==9419== by 0x8AC36E0: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x8AD9F5B: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x88461DB: g_param_spec_string (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x1153F1B7: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x8855925: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x883DDF0: g_object_newv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x883E38B: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x1153D7DF: gtk_settings_get_for_screen (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x114EC298: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x883A5C3: g_cclosure_marshal_VOID__OBJECTv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x8837406: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== 
==9419== 1 bytes in 1 blocks are possibly lost in loss record 4 of 5,210 
==9419== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 
==9419== by 0x8AC36E0: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x8AD9F5B: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x88461DB: g_param_spec_string (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x114E1933: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x8855925: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x170E3225: ??? (in /usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libcanberra-gtk-module.so) 
==9419== by 0x170E4FB1: gtk_module_init (in /usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libcanberra-gtk-module.so) 
==9419== by 0x114EB7F0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x883713F: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x884854F: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== by 0x88504AE: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1) 
==9419== 
//

等等,最後總結:

==9419== 32,768 bytes in 16 blocks are possibly lost in loss record 5,208 of 5,210 
==9419== at 0x4C2B4F0: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 
==9419== by 0x8AC377E: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x8A931C2: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x8A93632: g_array_insert_vals (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1) 
==9419== by 0x1151B084: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x1151B289: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x16EBA76B: ??? (in /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/engines/libmurrine.so) 
==9419== by 0x1151CBF0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x11521066: gtk_rc_get_style (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x115F2BEF: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x115F35BD: gtk_widget_realize (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== by 0x115F4187: gtk_widget_set_parent (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13) 
==9419== 
==9419== LEAK SUMMARY: 
==9419== definitely lost: 5,759 bytes in 31 blocks 
==9419== indirectly lost: 12,804 bytes in 396 blocks 
==9419==  possibly lost: 482,706 bytes in 2,236 blocks 
==9419== still reachable: 1,086,419 bytes in 7,493 blocks 
==9419==   suppressed: 0 bytes in 0 blocks 
==9419== Reachable blocks (those to which a pointer was found) are not shown. 
==9419== To see them, rerun with: --leak-check=full --show-reachable=yes 
==9419== 
==9419== For counts of detected and suppressed errors, rerun with: -v 
==9419== ERROR SUMMARY: 812 errors from 812 contexts (suppressed: 3 from 3) 
+0

一個簡單的Qt應用程序的valgrind輸出已經在[是否有人使用valgrind和Qt?]回答(http://stackoverflow.com/questions/1593717/is-anyone-using-valgrind-and-qt) –

+0

不,在那裏我的問題沒有答案。我該如何調試並避免錯誤報告? – 4pie0

+0

[是否有人使用valgrind和Qt?](http://stackoverflow.com/questions/1593717/is-anyone-using-valgrind-and-qt) – malat

回答

0

如果您確定您的應用程序正在泄漏內存,但它不是在Valgrind的檢測,那麼也許Velgrind是發現一些問題加載你的應用程序

如果您不確定,那麼您使用的庫可能會泄漏內存並且應該沒問題。

+0

我認爲OP意味着它相反,它檢測到沒有泄漏。 –