TINYGL: Fix some memory leaks

This commit is contained in:
Andrea Corna 2012-04-21 12:18:42 +02:00
parent a2b44ab930
commit bd14146a78
4 changed files with 20 additions and 1 deletions

View file

@ -17,6 +17,7 @@ void endSharedState(GLContext *c) {
GLSharedState *s = &c->shared_state; GLSharedState *s = &c->shared_state;
int i; int i;
free_texture(c, 0);
for (i = 0; i< MAX_DISPLAY_LISTS; i++) { for (i = 0; i< MAX_DISPLAY_LISTS; i++) {
// TODO // TODO
} }
@ -183,7 +184,13 @@ void glInit(void *zbuffer1) {
void glClose() { void glClose() {
GLContext *c = gl_get_context(); GLContext *c = gl_get_context();
specbuf_cleanup(c);
for (int i = 0; i < 3; i++)
gl_free(c->matrix_stack[i]);
endSharedState(c); endSharedState(c);
gl_free(c->vertex);
gl_free(c); gl_free(c);
} }

View file

@ -47,4 +47,14 @@ GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float s
return oldest; return oldest;
} }
void specbuf_cleanup(GLContext *c) {
GLSpecBuf *buf, *next;
buf = c->specbuf_first;
for (int i = 0; i < c->specbuf_num_buffers; ++i) {
next = buf->next;
gl_free(buf);
buf = next;
}
}
} // end of namespace TinyGL } // end of namespace TinyGL

View file

@ -17,7 +17,7 @@ static GLTexture *find_texture(GLContext *c, int h) {
return NULL; return NULL;
} }
static void free_texture(GLContext *c, int h) { void free_texture(GLContext *c, int h) {
GLTexture *t, **ht; GLTexture *t, **ht;
GLImage *im; GLImage *im;
int i; int i;

View file

@ -300,6 +300,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v);
void glInitTextures(GLContext *c); void glInitTextures(GLContext *c);
void glEndTextures(GLContext *c); void glEndTextures(GLContext *c);
GLTexture *alloc_texture(GLContext *c, int h); GLTexture *alloc_texture(GLContext *c, int h);
void free_texture(GLContext *c, int h);
// image_util.c // image_util.c
void gl_resizeImage(unsigned char *dest, int xsize_dest, int ysize_dest, void gl_resizeImage(unsigned char *dest, int xsize_dest, int ysize_dest,
@ -311,6 +312,7 @@ GLContext *gl_get_context();
// specular buffer "api" // specular buffer "api"
GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess); GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess);
void specbuf_cleanup(GLContext *c); // free all memory used
void glInit(void *zbuffer); void glInit(void *zbuffer);
void glClose(); void glClose();