正如文件所说:
(5) RRR -?-> BBB (y)DR, (n)DL
Pointer chain legend:
- RRR: a root set node or DR block
- AAA, BBB: heap blocks
- --->: a start-pointer
- -?->: an interior-pointer
Leak Case 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
void *RRR;
int main()
{
RRR = malloc(4);
RRR = (char*)RRR + 2;
return 0;
}
输出:
==3390== LEAK SUMMARY:
==3390== possibly lost: 4 bytes in 1 blocks
void *RRR;
int main()
{
RRR = malloc(4);
*(int*)RRR = 4;
RRR = (char*)RRR + 2;
return 0;
}
输出:
==3414== LEAK SUMMARY:
==3414== possibly lost: 4 bytes in 1 blocks
两种情况输出相同的结果。 '真正的指针' 意味着什么?并且' _'代表什么?
(y)XY: it's XY if the interior-pointer is a real pointer
。如何将XY
更改为真正的指针?
答案 0 :(得分:0)
我知道这是一个有点老问题,但也许将来对某人有帮助。
您的问题与"真实指针"有关。在以下文件陈述中:
- (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
此陈述与内部指针有关。文档说内部指针可能是:
它可能是记忆中的随机垃圾值,完全不相关,只是巧合。
在这种情况下,内部指针不被视为真实指针,因此在这种情况下
(5) RRR -?-> BBB (y)DR, (n)DL
将被视为直接丢失的内存((n)DL)。如果内部指针是指针变量,但是例如高级指向已分配内存块的中间位置,就像在案例2中所做的那样,它被认为是直接可达的((y)DR)。
请注意,这是我对文档的理解,而且我是