Skip to content

Detecting memory leaks

Yulei Sui edited this page Apr 10, 2020 · 22 revisions

Compile your project into LLVM bc files

clang -c -emit-llvm -g example.c -o example.bc

To compile a complicated real-world project you may wish to use WLLVM guide to install it.

Run Saber's leak detector on the generated bc file

saber -leak example.bc

Print the leak results when analyzing this test case

*********CallGraph Stats***************
################ (program : )###############
-------------------------------------------------------
TotalNode           27
TotalEdge           23
TotalCycle          0
NodeInCycle         0
MaxNodeInCycle      0
CalRetPairInCycle   0
#######################################################

*********General Stats***************
################ (program : )###############
TotalPointers       270
TotalObjects        70
TotalFieldObjects   1
MaxStructSize       0
TotalPAGEdges       379
FunctionObjs        27
GlobalObjs          0
HeapObjs            8
StackObjs           34
FIObjNum            0
FSObjNum            69
VarStructObj        0
VarArrayObj         1
ConstStructObj      0
ConstArrayObj       0
NonPtrObj           42
AddrsNum            78
LoadsNum            15
StoresNum           35
CopysNum            39
GepsNum             14
CallsNum            2
ReturnsNum          2
IndCallSites        0
TotalPTAPAGEdges    146
TotalCallSite       23
LocalVarInRecur     0
BitCastNumber       4
BBWith2Succ         1
BBWith3Succ         0
-------------------------------------------------------
#######################################################

*********Constraint Graph Stats***************
################ (program : )###############
-------------------------------------------------------
AvgIn/OutCopyEdge   0.362245
AvgIn/OutLoadEdge   0.0357143
AvgIn/OutAddrEdge   0.372449
AvgIn/OutEdge       0.872449
NumOfCGNode         371
TotalValidNode      196
TotalValidObjNode   69
NumOfCGEdge         98
NumOfAddrs          73
NumOfCopys          57
NumOfGeps           14
NumOfLoads          7
NumOfStores         20
MaxInCopyEdge       1
MaxOutCopyEdge      18
MaxInLoadEdge       1
MaxOutLoadEdge      4
MaxInStoreEdge      1
MaxOutStoreEdge     1
AvgIn/OutStoreEdge  0
MaxInAddrEdge       1
MaxOutAddrEdge      5
#######################################################

*********Andersen Pointer Analysis Stats***************
################ (program : )###############
-------------------------------------------------------
TotalTime           0.003
SCCDetectTime       0
SCCMergeTime        0
LoadStoreTime       0.001
CopyGepTime         0.001
UpdateCGTime        0
AvgPtsSetSize       0.291105
AvgTopLvlPtsSize    0.990654
CollapseTime        0
TotalPointers       270
TotalObjects        71
AddrProcessed       73
LoadProcessed       6
StoreProcessed      19
CopyProcessed       21
GepProcessed        14
NumOfSFRs           0
NumOfFieldExpand    0
Pointers            268
DYFieldPtrs         2
MemObjects          70
DYFieldObjs         1
MaxPtsSetSize       1
Iterations          2
IndCallSites        0
IndEdgeSolved       0
NumOfSCCDetect      2
TotalCycleNum       0
TotalPWCCycleNum    0
NodesInCycles       0
MaxNodesInSCC       0
NullPointer         0
PointsToConstPtr    1
PointsToBlkPtr      0
#######################################################

****Memory SSA Statistics****

************************
################ (program : )###############
-------------------------------------------------------
TotalMSSATime       0.001
GenRegionTime       0
GenMUCHITime        0
InsertPHITime       0
SSARenameTime       0.001
AverageRegSize      1
MaxRegSize          1
MemRegions          28
FunEntryChi         29
FunRetMu            29
CSChiNode           8
CSMuNode            8
LoadMuNode          7
StoreChiNode        20
MSSAPhi             0
FunHasEntryChi      19
FunHasRetMu         20
CSHasChi            8
CSHasMu             8
LoadHasMu           7
StoreHasChi         20
BBHasMSSAPhi        0
#######################################################

****SVFG Statistics****

************************
################ (program : )###############
-------------------------------------------------------
TotalTime           0
ConnDirEdgeTime     0
ConnIndEdgeTime     0
TLNodeTime          0
ATNodeTime          0
OptTime             0
AvgWeight           1
MSSAPhi             0
TotalNode           165
FormalIn            9
FormalOut           0
FormalParam         0
FormalRet           0
ActualIn            0
ActualOut           8
ActualParam         1
ActualRet           0
Addr                73
Copy                30
Gep                 14
Store               20
Load                7
PHI                 2
TotalEdge           76
DirectEdge          67
IndirectEdge        9
IndCallEdge         1
IndRetEdge          1
DirectCallEdge      1
DirectRetEdge       1
AvgInDegree         0
AvgOutDegree        0
MaxInDegree         1
MaxOutDegree        18
AvgIndInDeg         1
AvgIndOutDeg        1
MaxIndInDeg         1
MaxIndOutDeg        4
#######################################################
	 PartialLeak : memory allocation at : (ln: 23 fl: sp1.c)
		 conditional free path: 
		  --> (ln: 12 fl: sp1.c)