summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2004-08-13 22:29:39 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2004-08-13 22:29:39 +0000
commite61e2d74e1aec501de8ca68f22e7fcd95f5e7413 (patch)
treeba84f994b053fcffe5c5039a282202be0275c2b4
parent7fb051191450122e1a0aace6a89aae74b00e8c05 (diff)
downloadmesa_6_0_branch.tar.gz
fix some memory leaks (bug #1002030)mesa_6_0_branch
-rw-r--r--src/mesa/main/context.c40
-rw-r--r--src/mesa/main/depth.c10
-rw-r--r--src/mesa/main/occlude.c54
-rw-r--r--src/mesa/main/occlude.h7
-rw-r--r--src/mesa/main/program.c42
-rw-r--r--src/mesa/main/program.h3
6 files changed, 110 insertions, 46 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index e554f7508e7..0bc1381236b 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -6,9 +6,9 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.0.2
*
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -893,8 +893,10 @@ alloc_shared_state( GLcontext *ctx )
if (ss->DefaultFragmentProgram)
_mesa_delete_program(ctx, ss->DefaultFragmentProgram);
#endif
+#if FEATURE_ARB_vertex_buffer_object
if (ss->BufferObjects)
_mesa_DeleteHashTable(ss->BufferObjects);
+#endif
if (ss->Default1D)
(*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
@@ -940,6 +942,13 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
/* Free texture objects */
ASSERT(ctx->Driver.DeleteTexture);
+ /* the default textures */
+ (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
+ (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
+ (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
+ (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
+ (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
+ /* all other textures */
while (1) {
GLuint texName = _mesa_HashFirstEntry(ss->TexObjects);
if (texName) {
@@ -972,9 +981,16 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
}
_mesa_DeleteHashTable(ss->Programs);
#endif
+#if FEATURE_ARB_vertex_program
+ _mesa_delete_program(ctx, ss->DefaultVertexProgram);
+#endif
+#if FEATURE_ARB_fragment_program
+ _mesa_delete_program(ctx, ss->DefaultFragmentProgram);
+#endif
+#if FEATURE_ARB_vertex_buffer_object
_mesa_DeleteHashTable(ss->BufferObjects);
-
+#endif
_glthread_DESTROY_MUTEX(ss->Mutex);
FREE(ss);
@@ -1499,19 +1515,11 @@ _mesa_free_context_data( GLcontext *ctx )
_mesa_free_matrix_data( ctx );
_mesa_free_viewport_data( ctx );
_mesa_free_colortables_data( ctx );
-#if FEATURE_NV_vertex_program
- if (ctx->VertexProgram.Current) {
- ctx->VertexProgram.Current->Base.RefCount--;
- if (ctx->VertexProgram.Current->Base.RefCount <= 0)
- _mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base));
- }
-#endif
-#if FEATURE_NV_fragment_program
- if (ctx->FragmentProgram.Current) {
- ctx->FragmentProgram.Current->Base.RefCount--;
- if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
- _mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base));
- }
+ _mesa_free_program_data( ctx );
+ _mesa_free_occlude_data(ctx);
+
+#if FEATURE_ARB_vertex_buffer_object
+ _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
#endif
/* Shared context state (display lists, textures, etc) */
diff --git a/src/mesa/main/depth.c b/src/mesa/main/depth.c
index eb8c8b821b2..f758fc5b806 100644
--- a/src/mesa/main/depth.c
+++ b/src/mesa/main/depth.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.0.2
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -177,10 +177,4 @@ void _mesa_init_depth( GLcontext * ctx )
ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
}
ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
-
-#if FEATURE_ARB_occlusion_query
- ctx->Occlusion.QueryObjects = _mesa_NewHashTable();
-#endif
- ctx->OcclusionResult = GL_FALSE;
- ctx->OcclusionResultSaved = GL_FALSE;
}
diff --git a/src/mesa/main/occlude.c b/src/mesa/main/occlude.c
index d329f11f098..bc61a475d66 100644
--- a/src/mesa/main/occlude.c
+++ b/src/mesa/main/occlude.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 6.1
+ * Version: 6.0.2
*
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
@@ -45,20 +45,6 @@ struct occlusion_query
};
-
-void
-_mesa_init_occlude(GLcontext *ctx)
-{
-#if FEATURE_ARB_occlusion_query
- ctx->Occlusion.QueryObjects = _mesa_NewHashTable();
-#endif
-
- ctx->OcclusionResult = GL_FALSE;
- ctx->OcclusionResultSaved = GL_FALSE;
-}
-
-
-
/**
* Allocate a new occlusion query object.
* \param target - must be GL_SAMPLES_PASSED_ARB at this time
@@ -327,3 +313,41 @@ _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
return;
}
}
+
+
+
+/**
+ * Allocate/init the context state related to occlusion query objects.
+ */
+void
+_mesa_init_occlude(GLcontext *ctx)
+{
+#if FEATURE_ARB_occlusion_query
+ ctx->Occlusion.QueryObjects = _mesa_NewHashTable();
+#endif
+ ctx->OcclusionResult = GL_FALSE;
+ ctx->OcclusionResultSaved = GL_FALSE;
+}
+
+
+/**
+ * Free the context state related to occlusion query objects.
+ */
+void
+_mesa_free_occlude_data(GLcontext *ctx)
+{
+ while (1) {
+ GLuint query = _mesa_HashFirstEntry(ctx->Occlusion.QueryObjects);
+ if (query) {
+ struct occlusion_query *q = (struct occlusion_query *)
+ _mesa_HashLookup(ctx->Occlusion.QueryObjects, query);
+ ASSERT(q);
+ delete_query_object(q);
+ _mesa_HashRemove(ctx->Occlusion.QueryObjects, query);
+ }
+ else {
+ break;
+ }
+ }
+ _mesa_DeleteHashTable(ctx->Occlusion.QueryObjects);
+}
diff --git a/src/mesa/main/occlude.h b/src/mesa/main/occlude.h
index 5696463aecf..acf19101f14 100644
--- a/src/mesa/main/occlude.h
+++ b/src/mesa/main/occlude.h
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.0.2
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -30,6 +30,9 @@
extern void
_mesa_init_occlude(GLcontext *ctx);
+extern void
+_mesa_free_occlude_data(GLcontext *ctx);
+
extern void GLAPIENTRY
_mesa_GenQueriesARB(GLsizei n, GLuint *ids);
diff --git a/src/mesa/main/program.c b/src/mesa/main/program.c
index bdcc51f7b9b..1e3f365c449 100644
--- a/src/mesa/main/program.c
+++ b/src/mesa/main/program.c
@@ -47,7 +47,7 @@
/**
- * Init context's program state
+ * Init context's vertex/fragment program state
*/
void
_mesa_init_program(GLcontext *ctx)
@@ -81,6 +81,37 @@ _mesa_init_program(GLcontext *ctx)
/**
+ * Free a context's vertex/fragment program state
+ */
+void
+_mesa_free_program_data(GLcontext *ctx)
+{
+#if FEATURE_NV_vertex_program
+ if (ctx->VertexProgram.Current) {
+ ctx->VertexProgram.Current->Base.RefCount--;
+ if (ctx->VertexProgram.Current->Base.RefCount <= 0) {
+ _mesa_HashRemove(ctx->Shared->Programs,
+ ctx->VertexProgram.Current->Base.Id);
+ _mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base));
+ }
+ }
+#endif
+#if FEATURE_NV_fragment_program
+ if (ctx->FragmentProgram.Current) {
+ ctx->FragmentProgram.Current->Base.RefCount--;
+ if (ctx->FragmentProgram.Current->Base.RefCount <= 0) {
+ _mesa_HashRemove(ctx->Shared->Programs,
+ ctx->FragmentProgram.Current->Base.Id);
+ _mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base));
+ }
+ }
+#endif
+ _mesa_free((void *) ctx->Program.ErrorString);
+}
+
+
+
+/**
* Set the vertex/fragment program error state (position and error string).
* This is generally called from within the parsers.
*/
@@ -180,8 +211,8 @@ _mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id)
/**
- * Delete a program and remove it from the hash table, ignoring the
- * reference count.
+ * Delete a program, ignoring the reference count.
+ * Don't remove it from the hash table, the caller should do that.
*/
void
_mesa_delete_program(GLcontext *ctx, struct program *prog)
@@ -195,15 +226,16 @@ _mesa_delete_program(GLcontext *ctx, struct program *prog)
struct vertex_program *vprog = (struct vertex_program *) prog;
if (vprog->Instructions)
_mesa_free(vprog->Instructions);
+ if (vprog->Parameters)
+ _mesa_free_parameter_list(vprog->Parameters);
}
else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
struct fragment_program *fprog = (struct fragment_program *) prog;
if (fprog->Instructions)
_mesa_free(fprog->Instructions);
- if (fprog->Parameters) {
+ if (fprog->Parameters)
_mesa_free_parameter_list(fprog->Parameters);
- }
}
_mesa_free(prog);
}
diff --git a/src/mesa/main/program.h b/src/mesa/main/program.h
index 3c2aa1cdac6..53cd418d1c3 100644
--- a/src/mesa/main/program.h
+++ b/src/mesa/main/program.h
@@ -48,6 +48,9 @@ extern void
_mesa_init_program(GLcontext *ctx);
extern void
+_mesa_free_program_data(GLcontext *ctx);
+
+extern void
_mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string);
extern const GLubyte *