我正在 QT Creator 中编写一个程序,我只在 main.cpp 函数中使用这两行:
QString a = "10.98";
double b = a.toDouble();
一切似乎都很好,但是当我用 valgrind 检查它时,它报告了内存泄漏:
valgrind --leak-check=full ./Example
(...)
==15937==
==15937== 242 (96 direct, 146 indirect) bytes in 1 blocks are definitely lost in loss record 50 of 60
==15937== at 0x4C2C154: operator new(unsigned long) (vg_replace_malloc.c:298)
==15937== by 0x533710E: ??? (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x53373DA: QLibrary::setFileNameAndVersion(QString const&, QString const&) (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x533744B: QLibrary::QLibrary(QString const&, QString const&, QObject*) (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x52A3894: ??? (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x5269F10: QLocalePrivate::updateSystemPrivate() (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x526A1EA: ??? (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x526A21C: ??? (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x526A389: QLocale::QLocale() (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x52923F3: QString::toDouble(bool*) const (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.1)
==15937== by 0x40110D: main (in /host/Users/Tereza/Documents/CVUT-FSv/8.semestr/BP/example/Example)
==15937==
==15937== LEAK SUMMARY:
==15937== definitely lost: 192 bytes in 2 blocks
==15937== indirectly lost: 284 bytes in 6 blocks
==15937== possibly lost: 0 bytes in 0 blocks
==15937== still reachable: 19,931 bytes in 58 blocks
==15937== suppressed: 0 bytes in 0 blocks
==15937== Reachable blocks (those to which a pointer was found) are not shown.
==15937== To see them, rerun with: --leak-check=full --show-reachable=yes
==15937==
==15937== For counts of detected and suppressed errors, rerun with: -v
==15937== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
错误不可能出现在其他任何地方,因为只有这两行。
谁能解释我有什么问题?谢谢。
编辑:经过几次实验,我发现这可能不是由该操作引起的,而是可能与某些系统设置或类似的东西有关。我在使用不同的函数时遇到了类似的错误,并且总是 valgrind 报告与函数相关的前四行(如上)相同的原因QLibrary::setFileNameAndVersion()
。无论如何,有人知道这是什么原因吗?