fix possible segfault on destroy context
authorKeith Whitwell <keith@tungstengraphics.com>
Wed, 9 May 2001 13:53:36 +0000 (13:53 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Wed, 9 May 2001 13:53:36 +0000 (13:53 +0000)
src/mesa/tnl/t_context.c
src/mesa/tnl/t_imm_alloc.c
src/mesa/tnl/t_imm_exec.c

index bea2e37..f528208 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_context.c,v 1.16 2001/03/19 02:25:36 keithw Exp $ */
+/* $Id: t_context.c,v 1.17 2001/05/09 13:53:36 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -132,10 +132,8 @@ _tnl_DestroyContext( GLcontext *ctx )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
 
-/*     _tnl_dlist_destroy( ctx ); */
    _tnl_array_destroy( ctx );
    _tnl_imm_destroy( ctx );
-/*     _tnl_eval_destroy( ctx ); */
    _tnl_destroy_pipeline( ctx );
 
    FREE(tnl);
index 2b497a7..22bdb7a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_imm_alloc.c,v 1.7 2001/04/30 21:08:52 keithw Exp $ */
+/* $Id: t_imm_alloc.c,v 1.8 2001/05/09 13:53:36 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -118,14 +118,21 @@ struct immediate *_tnl_alloc_immediate( GLcontext *ctx )
       return real_alloc_immediate( ctx );
 }
 
+/* May be called after tnl is destroyed.
+ */
 void _tnl_free_immediate( struct immediate *IM )
 {
    TNLcontext *tnl = TNL_CONTEXT(IM->backref);
 
    ASSERT(IM->ref_count == 0);
 
-   if (tnl->freed_immediate)
-      real_free_immediate( tnl->freed_immediate );
-   
-   tnl->freed_immediate = IM;
+   if (!tnl) {
+      real_free_immediate( IM );
+   } 
+   else {
+      if (tnl->freed_immediate)
+        real_free_immediate( tnl->freed_immediate );
+      
+      tnl->freed_immediate = IM;
+   }
 }
index 25de9a2..adb79ab 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_imm_exec.c,v 1.21 2001/05/03 16:49:27 keithw Exp $ */
+/* $Id: t_imm_exec.c,v 1.22 2001/05/09 13:53:36 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -554,7 +554,8 @@ void _tnl_imm_destroy( GLcontext *ctx )
 {
    if (TNL_CURRENT_IM(ctx)) {
       TNL_CURRENT_IM(ctx)->ref_count--;
-      _tnl_free_immediate( TNL_CURRENT_IM(ctx) );
+      if (TNL_CURRENT_IM(ctx)->ref_count == 0)
+        _tnl_free_immediate( TNL_CURRENT_IM(ctx) );
       SET_IMMEDIATE(ctx, 0);
    }
 }