]> Pileus Git - grits/blobdiff - src/objects/grits-tile.c
Fix a variety of memory leaks
[grits] / src / objects / grits-tile.c
index e2aeb4542118550037bba1c97a3a0a612eb6aaa8..6ea70f88cbf052e38073b8087e3ea300c7f19c79 100644 (file)
  * representing the OpenGL texture to use when drawing the tile.
  */
 
+#define GL_GLEXT_PROTOTYPES
 #include <config.h>
 #include <math.h>
+#include <string.h>
 #include "gtkgl.h"
 #include "grits-tile.h"
 
-guint  grits_tile_mask = 0;
+static guint  grits_tile_mask = 0;
 
 gchar *grits_tile_path_table[2][2] = {
        {"00.", "01."},
@@ -347,19 +349,22 @@ void grits_tile_free(GritsTile *root, GritsTileFreeFunc free_func, gpointer user
 /* Load texture mask so we can draw a texture to just a part of a triangle */
 static guint _grits_tile_load_mask(void)
 {
-       guint  tex;
-       guint8 byte = 0xff;
+       guint tex;
+       const int width = 256, height = 256;
+       guint8 *bytes = g_malloc(width*height);
+       memset(bytes, 0xff, width*height);
        glGenTextures(1, &tex);
        glBindTexture(GL_TEXTURE_2D, tex);
 
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0,
-                       GL_ALPHA, GL_UNSIGNED_BYTE, &byte);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0,
+                       GL_ALPHA, GL_UNSIGNED_BYTE, bytes);
 
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+       g_free(bytes);
        return tex;
 }