gpt4 book ai didi

valgrind - valgrind中可能丢失的含义是什么

转载 作者:行者123 更新时间:2023-12-04 13:07:32 26 4
gpt4 key购买 nike

我有很多可能从 valgrind 丢失的条目。这意味着什么 ?
因为我正在使用 sqlite 并且它经过了很好的测试。我不认为这些是正确的条目。我做错了什么?

 16 bytes in 1 blocks are possibly lost in loss record 30 of 844
==23027== at 0x4A05E1C: malloc (vg_replace_malloc.c:195)
==23027== by 0x6525BE: sqlite3MemMalloc (in app_mem.out)
==23027== by 0x63C579: mallocWithAlarm (in app_mem.out)
==23027== by 0x63C904: sqlite3DbMallocRaw (in app_mem.out)
==23027== by 0x6886D6: codeOneLoopStart (in app_mem.out)
==23027== by 0x68A9C8: sqlite3WhereBegin (in app_mem.out)
==23027== by 0x68CC9E: sqlite3Select (in app_mem.out)
==23027== by 0x6A8644: yy_reduce (in app_mem.out)
==23027== by 0x6AAEAC: sqlite3Parser (in app_mem.out)
==23027== by 0x6AB357: sqlite3RunParser (in app_mem.out)
==23027== by 0x6ADF84: sqlite3Prepare (in app_mem.out)
==23027== by 0x6AE82B: sqlite3LockAndPrepare (in app_mem.out)

最佳答案

Valgrind 源代码 3.6.1 版中包含的常见问题解答确实详细说明了一点:

"possibly lost" means your program is leaking memory, unless you're doing unusual things with pointers that could cause them to point into the middle of an allocated block; see the user manual for some possible causes. Use --show-possibly-lost=no if you don't want to see these reports.



(5.2. 杂项,Valgrind 常见问题解答)

Valgrind 用户手册讨论了它如何跟踪使用 malloc/new 分配的所有堆 block ,并描述了两种跟踪内存的方法:
  • 通过维护指向内存块开始的“开始指针”
  • 通过维护指向 block 中间某个位置的“内部指针”

  • 可能出现内部指针的三种情况:
  • 该指针可能最初是一个起始指针,并且已被程序故意(或非故意)移动。
  • 它可能是内存中的随机垃圾值,完全不相关,只是巧合。
  • 它可能是指向使用 new[] 分配的 C++ 对象(具有析构函数)数组的指针。

  • 可能的场景:
         Pointer chain            AAA Category    BBB Category
    ------------- ------------ ------------
    (5) RRR ------?-----> BBB (y)DR, (n)DL
    (6) RRR ---> AAA -?-> BBB DR (y)IR, (n)DL
    (7) RRR -?-> AAA ---> BBB (y)DR, (n)DL (y)IR, (n)IL
    (8) RRR -?-> AAA -?-> BBB (y)DR, (n)DL (y,y)IR, (n,y)IL, (_,n)DL

    Pointer chain legend:
    - RRR: a root set node or DR block
    - AAA, BBB: heap blocks
    - --->: a start-pointer
    - -?->: an interior-pointer

    Category legend:
    - DR: Directly reachable
    - IR: Indirectly reachable
    - DL: Directly lost
    - IL: Indirectly lost
    - (y)XY: it's XY if the interior-pointer is a real pointer
    - (n)XY: it's XY if the interior-pointer is not a real pointer
    - (_)XY: it's XY in either case

    (4.2.7. 内存泄漏检测,Valgrind 用户手册)

    事实证明,警告“可能丢失”涵盖了上面的案例 5-8(针对 BBB) block 。

    This means that a chain of one or more pointers to the block has been found, but at least one of the pointers is an interior-pointer. This could just be a random value in memory that happens to point into a block, and so you shouldn't consider this ok unless you know you have interior-pointers.



    (4.2.7. 内存泄漏检测,Valgrind 用户手册)

    因此,我们以一种相当冗长的方式得出与 fbafelipe 相同的结论,即;假设您正确使用 API,或者 sqlite 泄漏了一点内存,或者它正在参与上述有效案例之一。鉴于 sqlite 项目的成熟度,可以安全地假设警告不会引起太多关注。

    如果您提供有关如何使用 api(以及在什么情况下发生泄漏)的更多信息,其他人可能能够提供更多见解。

    引用: Valgrind 3.6.1 source, doc/faq.html, doc/mc-manual.html

    关于valgrind - valgrind中可能丢失的含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6771610/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com