draw: Fix memory leaks in llvm code.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 30 Apr 2010 18:00:58 +0000 (19:00 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 30 Apr 2010 18:32:20 +0000 (19:32 +0100)
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c

index 3b2df054c3c0ce881f494f2adaca54be479f49f8..2c234285b5e0b968b201d754ca08bd38c7dae889 100644 (file)
@@ -207,6 +207,8 @@ draw_llvm_create(struct draw_context *draw)
 void
 draw_llvm_destroy(struct draw_llvm *llvm)
 {
+   LLVMDisposePassManager(llvm->pass);
+
    FREE(llvm);
 }
 
index d2a492f2b4cd1e2d688696d5950c9c100e04e6d4..35913a599515cf23642df3c6563888f639038817 100644 (file)
@@ -349,7 +349,31 @@ static void llvm_middle_end_finish( struct draw_pt_middle_end *middle )
 static void llvm_middle_end_destroy( struct draw_pt_middle_end *middle )
 {
    struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle;
+   struct draw_context *draw = fpme->draw;
+   struct draw_llvm_variant *variant = NULL;
+
+   variant = fpme->variants;
+   while(variant) {
+      struct draw_llvm_variant *next = variant->next;
 
+      if (variant->function_elts) {
+         if (variant->function_elts)
+            LLVMFreeMachineCodeForFunction(draw->engine,
+                                           variant->function_elts);
+         LLVMDeleteFunction(variant->function_elts);
+      }
+
+      if (variant->function) {
+         if (variant->function)
+            LLVMFreeMachineCodeForFunction(draw->engine,
+                                           variant->function);
+         LLVMDeleteFunction(variant->function);
+      }
+
+      FREE(variant);
+
+      variant = next;
+   }
    if (fpme->fetch)
       draw_pt_fetch_destroy( fpme->fetch );