Just in time for Mesa-3.1beta3 :-).  I now have what I believe to be a
very clean fix for the memory leaks I've observed.  Some were rather
simple ommisions from the contexts' destructor (gl_matrix_dtr() and
gl_extensions_dtr() calls), but the immediate buffers were more
tricky.  Let me repeat that those leaks were quite serious and could
easily reach hundreds of kB per allocated/destroyed GLX context.

Regards,
Wolfram.

--- src/vb.c    1999/09/18 13:52:09     1.1
+++ src/vb.c    1999/09/19 14:16:46
@@ -92,7 +92,8 @@
    
 
    VB->prev_buffer = IM;
-   IM->ref_count++;    /* needed? */
+   /* prev_buffer is now also a reference for the immediate buffer */
+   IM->ref_count++;
 
    if (ctx->Driver.RegisterVB)
       ctx->Driver.RegisterVB( VB );
@@ -197,8 +198,11 @@
    gl_vector4ub_free( &VB->BColor );
    gl_vector1ui_free( &VB->BIndex );
 
+   if ( VB->prev_buffer && ! --VB->prev_buffer->ref_count )
+      gl_immediate_free( VB->prev_buffer );
    if (VB->IM) {
-      gl_immediate_free( VB->IM );
+      if ( ! --VB->IM->ref_count )
+        gl_immediate_free( VB->IM );
 
       free( VB->CullMask );
       free( VB->NormCullMask );
@@ -234,6 +238,8 @@
 
    if (VB->ctx->Driver.UnregisterVB)
       VB->ctx->Driver.UnregisterVB( VB );
+
+   free( VB );
 }
 
 
@@ -302,11 +308,3 @@
       ctx->nr_im_queued++; 
    }
 }
-
-
-
-
-
-
-
-
--- src/context.c.orig  Sun Sep 12 09:00:05 1999
+++ src/context.c       Sun Sep 19 16:07:53 1999
@@ -1350,10 +1350,17 @@
       for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
         gl_matrix_dtr( &ctx->ModelViewStack[i] );
       }
-
+      gl_matrix_dtr( &ctx->ProjectionMatrix );
+      for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
+        gl_matrix_dtr( &ctx->ProjectionStack[i] );
+      }
 
       free( ctx->PB );
-      free( ctx->VB );
+
+      if(ctx->input != ctx->VB->IM)
+         gl_immediate_free( ctx->input );
+
+      gl_vb_free( ctx->VB );
 
       ctx->Shared->RefCount--;
       assert(ctx->Shared->RefCount>=0);
@@ -1410,6 +1417,14 @@
          free( ctx->EvalMap.Map2Texture3.Points );
       if (ctx->EvalMap.Map2Texture4.Points)
          free( ctx->EvalMap.Map2Texture4.Points );
+
+      /* Free cache of immediate buffers. */
+      while (ctx->nr_im_queued-- > 0) {
+         struct immediate * next = ctx->freed_im_queue->next;
+         free( ctx->freed_im_queue );
+         ctx->freed_im_queue = next;
+      }
+      gl_extensions_dtr(ctx);
 
       free( (void *) ctx );
 


-- 
`Surf the sea, not double-u three...'
[EMAIL PROTECTED]


_______________________________________________
Mesa-dev maillist  -  [EMAIL PROTECTED]
http://lists.mesa3d.org/mailman/listinfo/mesa-dev

Reply via email to