Hi,

I'm seeing several significant memory leaks in MesaCVS-Sep05 at the
`repeat: create context, draw, destroy context' level.

The most significant ones seems to be from gl_immediate_alloc().
I haven't yet managed to unterstand the refcounting for
`struct immediate's.  However, the appended patch for context.c
seems to be necessary in any case:

--- context.c   1999/09/09 21:14:50     1.1
+++ context.c   1999/09/11 11:48:09
@@ -1355,7 +1355,11 @@
 
 
       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);
@@ -1412,6 +1416,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;
+         /*printf("free_im(%p)\n", ctx->freed_im_queue);*/
+         free(ctx->freed_im_queue);
+         ctx->freed_im_queue = next;
+      }
 
       free( (void *) ctx );
 

There is another possibility for struct immediate to leak when it is
put in a compiled display list.  The following is obviously _not_ the
correct fix, the refcounting should be fixed instead:

--- dlist.c     1999/09/11 09:16:42     1.1
+++ dlist.c     1999/09/11 11:34:37
@@ -348,11 +348,14 @@
    while (!done) {
       switch (n[0].opcode) {
         /* special cases first */
-         case OPCODE_VERTEX_CASSETTE: 
-           if ( ! -- ((struct immediate *) n[1].data)->ref_count )
-              gl_immediate_free( (struct immediate *) n[1].data );
+         case OPCODE_VERTEX_CASSETTE: {
+           struct immediate* im = (struct immediate *) n[1].data;
+           if ( 1 || ! -- im->ref_count )
+              gl_immediate_free( im );
            n += InstSize[n[0].opcode];
-           break;
+           break; }
         case OPCODE_MAP1:
            gl_free_control_points( ctx, n[1].e, (GLfloat *) n[6].data );
            n += InstSize[n[0].opcode];

I'll keep looking to understand the refcounting, but others may
be quicker.  I'll also report the more minor leaks once this is
fixed.

Regards,
Wolfram.
-- 
`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