[PATCH] MipsAsmParser: Fix a couple of memory leaks

NAKAMURA Takumi geek4civic at gmail.com
Tue Apr 15 06:40:50 PDT 2014


Hi dsanders,

1. Manage Mem.Base.
2. Be responsible to release temporary Operands in MipsAsmParser::ParseRegister().

See also; http://lab.llvm.org:8011/builders/llvm-x86_64-linux-vg_leak
Feel free to rewrite and commit one as yourselves.

http://reviews.llvm.org/D3378

Files:
  llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Index: llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -756,6 +756,20 @@
   /// getEndLoc - Get the location of the last token of this operand.
   SMLoc getEndLoc() const { return EndLoc; }
 
+  virtual ~MipsOperand() {
+    switch (Kind) {
+    case k_Immediate:
+      break;
+    case k_Memory:
+      delete Mem.Base;
+      break;
+    case k_PhysRegister:
+    case k_RegisterIndex:
+    case k_Token:
+      break;
+    }
+  }
+
   virtual void print(raw_ostream &OS) const {
     switch (Kind) {
     case k_Immediate:
@@ -1586,6 +1600,8 @@
       RegNo = isGP64() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
     }
 
+    delete &Operand;
+
     return (RegNo == (unsigned)-1);
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3378.1.patch
Type: text/x-patch
Size: 877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140415/1bb421a5/attachment.bin>


More information about the llvm-commits mailing list