C++ と QML で記述されたプロジェクトがあり、Valgrind を使用してメモリ リークを調査しようとしましたが、アプリケーションが次のように可能な限り単純であっても、多数のエラーが表示されます。
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer->setMainQmlFile(QLatin1String("qml/Interface/main2.qml"));
viewer->showExpanded();
return app->exec();
}
QML ファイルは次のとおりです。
import QtQuick 1.0
Rectangle {
width: 800
height: 480
color: "blue"
MouseArea {
anchors.fill: parent
onClicked: Qt.quit()
}
}
次のコマンドを使用して Valgrind を実行しています。
valgrind -v --leak-check=full --show-reachable=yes --track-origins=yes --log-file=Interface2.valgrind.log ./Interface2
Valgrind の要約は次のように述べています。
==16840== LEAK SUMMARY:
==16840== definitely lost: 344 bytes in 2 blocks
==16840== indirectly lost: 20 bytes in 1 blocks
==16840== possibly lost: 9,935 bytes in 308 blocks
==16840== still reachable: 133,085 bytes in 2,234 blocks
==16840== suppressed: 0 bytes in 0 blocks
以下は、Valgrind から取得した (ログの約 3000 行の) いくつかのメッセージです。
==16840== Memcheck, a memory error detector
==16840== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==16840== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==16840== Command: ./Interface2
==16840== Parent PID: 13367
==16840==
--16840--
--16840-- Valgrind options:
--16840-- --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp
--16840-- -v
--16840-- --leak-check=full
--16840-- --show-reachable=yes
--16840-- --track-origins=yes
--16840-- --log-file=Interface2.valgrind.log
--16840-- Contents of /proc/version:
--16840-- Linux version 2.6.32-43-generic (buildd@roseapple) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1) ) #97-Ubuntu SMP Wed Sep 5 16:43:09 UTC 2012
--16840-- Arch and hwcaps: X86, x86-sse1-sse2
--16840-- Page sizes: currently 4096, max supported 4096
--16840-- Valgrind library directory: /usr/lib/valgrind
--16840-- Reading syms from /lib/ld-2.11.1.so (0x4000000)
--16840-- Reading debug info from /lib/ld-2.11.1.so ..
--16840-- .. CRC mismatch (computed 1f70923a wanted 671e42e8)
--16840-- Reading debug info from /usr/lib/debug/lib/ld-2.11.1.so ..
--16840-- Reading syms from /root/workspace/CC5/AIO_CC5/Tools/Interface/Interface2 (0x8048000)
--16840-- Reading syms from /usr/lib/valgrind/memcheck-x86-linux (0x38000000)
--16840-- object doesn't have a dynamic symbol table
--16840-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp
--16840-- Reading suppressions file: /usr/lib/valgrind/default.supp
--16840-- REDIR: 0x4016100 (index) redirected to 0x3803e9b3 (vgPlain_x86_linux_REDIR_FOR_index)
--16840-- Reading syms from /usr/lib/valgrind/vgpreload_core-x86-linux.so (0x401f000)
--16840-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so (0x4022000)
==16840== 148 (128 direct, 20 indirect) bytes in 1 blocks are definitely lost in loss record 133 of 200
==16840== at 0x4024F20: malloc (vg_replace_malloc.c:236)
==16840== by 0x60438C1: ??? (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x60443C4: ??? (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x60444D9: ??? (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x6048876: ??? (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x60493C0: ??? (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x61CACFD: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61CBBC0: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61CD412: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61CDCD9: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61C6F02: XML_ParseBuffer (in /lib/libexpat.so.1.5.2)
==16840== by 0x604724A: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.4.4)
==16840== 216 bytes in 1 blocks are definitely lost in loss record 137 of 200
==16840== at 0x4024F20: malloc (vg_replace_malloc.c:236)
==16840== by 0x60CE9D2: _XimOpenIM (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60CE817: _XimRegisterIMInstantiateCallback (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60B1D77: XRegisterIMInstantiateCallback (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x4BF6A51: ??? (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x4BF4500: QInputContextFactory::create(QString const&, QObject*) (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x4551C2C: QApplication::inputContext() const (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x459DEA6: QWidgetPrivate::inputContext() const (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x45A9E03: QWidget::setAttribute(Qt::WidgetAttribute, bool) (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x4C65E0B: QGraphicsViewPrivate::updateInputMethodSensitivity() (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x4C7185E: QGraphicsView::setScene(QGraphicsScene*) (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x40A5A06: ??? (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtDeclarative.so.4.7.4)
==16840== 256 bytes in 1 blocks are still reachable in loss record 143 of 200
==16840== at 0x4025016: realloc (vg_replace_malloc.c:525)
==16840== by 0x602ED60: FcBlanksAdd (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x60495CB: ??? (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x61CACFD: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61CBBC0: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61CD412: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61CDCD9: ??? (in /lib/libexpat.so.1.5.2)
==16840== by 0x61C6F02: XML_ParseBuffer (in /lib/libexpat.so.1.5.2)
==16840== by 0x604724A: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x603D091: FcInitLoadConfig (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x603D19B: FcInitLoadConfigAndFonts (in /usr/lib/libfontconfig.so.1.4.4)
==16840== by 0x603D29C: FcInit (in /usr/lib/libfontconfig.so.1.4.4)
==16840== 360 bytes in 3 blocks are possibly lost in loss record 144 of 200
==16840== at 0x4024106: memalign (vg_replace_malloc.c:581)
==16840== by 0x4024163: posix_memalign (vg_replace_malloc.c:709)
==16840== by 0x5E9C9C1: slab_allocator_alloc_chunk (gslice.c:1148)
==16840== by 0x5E9D222: g_slice_alloc (gslice.c:678)
==16840== by 0x5E9E881: g_slist_prepend (gslist.c:273)
==16840== by 0x5EA1A94: g_strsplit (gstrfuncs.c:2431)
==16840== by 0x5EB5731: g_get_language_names (gutils.c:3169)
==16840== by 0x5EA9B49: g_thread_init_glib (gthread.c:940)
==16840== by 0x5E3F69D: g_thread_init (gthread-impl.c:360)
==16840== by 0x50FC7D9: QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(_GMainContext*) (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtCore.so.4.7.4)
==16840== by 0x460CB4C: ??? (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x460CC32: ??? (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== 16,352 bytes in 2 blocks are still reachable in loss record 199 of 200
==16840== at 0x4024F20: malloc (vg_replace_malloc.c:236)
==16840== by 0x6098833: ??? (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x6098CA6: _XrmInternalStringToQuark (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x609F4C5: XStringToKeysym (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60D2849: _XimParseStringFile (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60D0466: _XimLocalOpenIM (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60CEB3C: _XimOpenIM (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60CE817: _XimRegisterIMInstantiateCallback (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x60B1D77: XRegisterIMInstantiateCallback (in /usr/lib/libX11.so.6.3.0)
==16840== by 0x4BF6A51: ??? (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x4BF4500: QInputContextFactory::create(QString const&, QObject*) (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
==16840== by 0x4551C2C: QApplication::inputContext() const (in /opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so.4.7.4)
問題は、アプリケーションからメモリ リーク エラーを取り除くために何をする必要があるかということです。これはバグのあるライブラリの問題ですか?Qt公式サイトのインストーラーを使用してインストールしました。
ありがとう。