2017-03-11 47 views
6

我編譯DEBUG_LEAKING_SCALARS Perl作爲描述here爲什麼在使用`DEBUG_LEAKING_SCALARS`編譯perl時不報告內存泄漏?

CASE 1
我按照這個DOC測試內存泄露報告:

env PERL_DESTRUCT_LEVEL=2 valgrind perl -e '@x; $x[0]=\@x' 
==7216== Memcheck, a memory error detector 
==7216== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. 
==7216== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info 
==7216== Command: perl -e @x;\ $x[0]=\\@x 
==7216== 
==7216== 
==7216== HEAP SUMMARY: 
==7216==  in use at exit: 0 bytes in 0 blocks 
==7216== total heap usage: 1,310 allocs, 1,310 frees, 171,397 bytes allocated 
==7216== 
==7216== All heap blocks were freed -- no leaks are possible 
==7216== 
==7216== For counts of detected and suppressed errors, rerun with: -v 
==7216== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 

沒有什麼報道。

CASE 2
我甚至在我的XS子做this thing。沒錯:

#define PERL_NO_GET_CONTEXT 
#include "EXTERN.h" 
#include "perl.h" 
#include "XSUB.h" 

#include "XSUtils.h" 
#include "ppport.h" 

void 
call_perl() { 
    SV *sv; 
    sv = sv_2mortal(newSVpv("XS::Utils::hello", 0)); 

    newSViv(323);  //<<<< SHOULD LEAK 
    printf("Hi 3\n"); 

    ENTERSCOPE; 
    CALLPERL(sv , G_DISCARD|G_NOARGS); 
    LEAVESCOPE; 
} 

MODULE = XS::Utils     PACKAGE = XS::Utils 

void 
test() 
    CODE: 
     call_perl(); 

Link to the REPO

$ env PERL_DESTRUCT_LEVEL=2 valgrind perl -Iblib/arch/ -Iblib/lib -MXS::Utils -e 'XS::Utils::test()' 
==7308== Memcheck, a memory error detector 
==7308== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. 
==7308== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info 
==7308== Command: perl -Iblib/arch/ -Iblib/lib -MXS::Utils -e XS::Utils::test() 
==7308== 
Hi 3 
Hello 
==7308== 
==7308== HEAP SUMMARY: 
==7308==  in use at exit: 1,502 bytes in 5 blocks 
==7308== total heap usage: 12,876 allocs, 12,871 frees, 1,945,298 bytes allocated 
==7308== 
==7308== LEAK SUMMARY: 
==7308== definitely lost: 0 bytes in 0 blocks 
==7308== indirectly lost: 0 bytes in 0 blocks 
==7308==  possibly lost: 0 bytes in 0 blocks 
==7308== still reachable: 1,502 bytes in 5 blocks 
==7308==   suppressed: 0 bytes in 0 blocks 
==7308== Rerun with --leak-check=full to see details of leaked memory 
==7308== 
==7308== For counts of detected and suppressed errors, rerun with: -v 
==7308== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 

沒有報道過

CASE 3
我修復模塊Devel::LeakTrace(該FIX):

$ perl -MDevel::LeakTrace -Iblib/arch/ -Iblib/lib -MXS::Utils -e 'XS::Utils::test()' 
Hi 3 
Hello 

沒有報道過

CASE 4
我只找到Test::LeakTrace做的工作:

$ perl -MTest::LeakTrace::Script=-verbose -Iblib/arch/ -Iblib/lib -MXS::Utils -e 'XS::Utils::test()' 
Hi 3 
Hello 
leaked SCALAR(0x208e1c0) from -e line 1. 
ALLOCATED at -e:1 by entersub (parent 0x0); serial 9642 
SV = IV(0x208e1b0) at 0x208e1c0 
    REFCNT = 1 
    FLAGS = (IOK,pIOK) 
    IV = 323 

爲什麼建在perl的報告一無所知泄漏的工具嗎?
我錯了什麼?如何使用DEBUG_LEAKING_SCALARS工具調試泄漏內存?

+0

你知道,也許你應該在#p5p上irc.perl.org上閒逛。我有這樣的感覺,那裏的人對你正在做的這些東西比我們這裏的人更精通。 :) – simbabque

+2

@simbabque ..,但作爲參考將很高興知道答案太:) :) :) – jm666

+0

@ jm666絕對。這對他來說非常有用,但是他每次都會在一兩天後發佈自己的答案。關於他在做什麼的背景可能是一個科技博客。 :D請繼續歐根。 – simbabque

回答

1

其實不是一個答案,但是從戴夫·米切爾

DEBUG_LEAKING_SCALARS的主要目的不是爲了列出泄露標量
(!!)
它在一般跟蹤下來的東西,以幫助涉及泄露的標量 和refcount問題。它的兩個主要特點是它將SV分配從一個宏變成一個函數,以便您可以輕鬆地將 附加一個斷點;並且它向每個顯示 的SV添加了儀器(Devel :: Peek顯示)。

但我不知道要調試什麼,因爲我不知道有什麼東西在泄漏。類似於上述的從1到3的個案。我確信:

newSViv(323); 

沒有泄漏。

所以DEBUG_LEAKING_SCALARS應該名單泄露標量

而且我發現在Perl的此評論提交歷史:

- [24088]通過:DAVEM於2005年3月28日21:38: 44
- 日誌:擴大-DDEBUG_LEAKING_SCALARS儀器每個SV的創建

這將是非常有用任務在我心中。

+0

這回答了爲什麼'DEBUG_LEAKING_SCALARS'沒有列出泄漏(因爲它的關鍵是使調試泄漏更容易,而不是首先確定泄漏),但它使得可疑和無法解釋的聲明「DEBUG_LEAKING_SCALARS」應該列出泄漏的標量,並沒有解釋爲什麼設計用於查找泄漏的工具('valgrind'和Devel :: LeakTrace)找不到它。 – ikegami

相關問題