[polly] r275546 - GPGPU: Free options to avoid memory leak

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 15 03:32:23 PDT 2016


Author: grosser
Date: Fri Jul 15 05:32:22 2016
New Revision: 275546

URL: http://llvm.org/viewvc/llvm-project?rev=275546&view=rev
Log:
GPGPU: Free options to avoid memory leak

ppcg does not free the option structs for us. To avoid a memory leak we do this
ourselves.

Modified:
    polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp

Modified: polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp?rev=275546&r1=275545&r2=275546&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp Fri Jul 15 05:32:22 2016
@@ -619,12 +619,26 @@ public:
     free(PPCGGen);
   }
 
+  /// Free the options in the ppcg scop structure.
+  ///
+  /// ppcg is not freeing these options for us. To avoid leaks we do this
+  /// ourselves.
+  ///
+  /// @param PPCGScop The scop referencing the options to free.
+  void freeOptions(ppcg_scop *PPCGScop) {
+    free(PPCGScop->options->debug);
+    PPCGScop->options->debug = nullptr;
+    free(PPCGScop->options);
+    PPCGScop->options = nullptr;
+  }
+
   bool runOnScop(Scop &CurrentScop) override {
     S = &CurrentScop;
 
     auto PPCGScop = createPPCGScop();
     auto PPCGProg = createPPCGProg(PPCGScop);
     auto PPCGGen = generateGPU(PPCGScop, PPCGProg);
+    freeOptions(PPCGScop);
     freePPCGGen(PPCGGen);
     gpu_prog_free(PPCGProg);
     ppcg_scop_free(PPCGScop);




More information about the llvm-commits mailing list