[LLVMdev] memory leak in method ContractNodes

wuhui1973 wuhui1973 at 163.com
Mon Oct 13 01:24:23 PDT 2014


Hello Hal:


There is memory leak in method ContractNodes (below code is from trunk):


26static void ContractNodes(std::unique_ptr<Matcher> &MatcherPtr,
27                          const CodeGenDAGPatterns &CGP) {
...
43  // transform it.
44  if (MoveChildMatcher *MC = dyn_cast<MoveChildMatcher>(N)) {
45    Matcher *New = nullptr;
46    if (RecordMatcher *RM = dyn_cast<RecordMatcher>(MC->getNext()))
47      if (MC->getChildNo() < 8)  // Only have RecordChild0...7
48        New = new RecordChildMatcher(MC->getChildNo(), RM->getWhatFor(),
49                                     RM->getResultNo());
50
51    if (CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(MC->getNext()))
52      if (MC->getChildNo() < 8 &&  // Only have CheckChildType0...7
53          CT->getResNo() == 0)     // CheckChildType checks res #0
---> We should delete previous allocated New here!
54        New = new CheckChildTypeMatcher(MC->getChildNo(), CT->getType());
55
56    if (CheckSameMatcher *CS = dyn_cast<CheckSameMatcher>(MC->getNext()))
57      if (MC->getChildNo() < 4)  // Only have CheckChildSame0...3
---> We should delete previous allocated New here!
58        New = new CheckChildSameMatcher(MC->getChildNo(), CS->getMatchNumber());
59
60    if (CheckIntegerMatcher *CS = dyn_cast<CheckIntegerMatcher>(MC->getNext()))
61      if (MC->getChildNo() < 5)  // Only have CheckChildInteger0...4
---> We should delete previous allocated New here!
62        New = new CheckChildIntegerMatcher(MC->getChildNo(), CS->getValue());
63
64    if (New) {
65      // Insert the new node.
66      New->setNext(MatcherPtr.release());
67      MatcherPtr.reset(New);
68      // Remove the old one.
69      MC->setNext(MC->getNext()->takeNext());
70      return ContractNodes(MatcherPtr, CGP);
71    }




Regards
Hui Wu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141013/031b98ec/attachment.html>


More information about the llvm-dev mailing list