Commit e61e2d74 authored by Brian Paul's avatar Brian Paul
Browse files

fix some memory leaks (bug #1002030)

parent 7fb05119
......@@ -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) */
......
/*
* 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;
}
/*
* 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);
}
/*
* 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);
......
......@@ -47,7 +47,7 @@
/**
* Init context's program state
* Init context's vertex/fragment program state
*/
void
_mesa_init_program(GLcontext *ctx)
......@@ -80,6 +80,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);
}
......
......@@ -47,6 +47,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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment