i965: Fix oversized initial allocation of the state cache table pointers.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_cache.c
index 92b81c7ad174099a2c26f9f9491e43fbe95c82fa..d44b2b7c5b926808d25f5f84b5dd1ebab9317749 100644 (file)
@@ -49,6 +49,7 @@
 #include "brw_state.h"
 #include "brw_vs.h"
 #include "brw_wm.h"
+#include "brw_vs.h"
 
 #define FILE_DEBUG_FLAG DEBUG_STATE
 
@@ -335,7 +336,7 @@ brw_init_caches(struct brw_context *brw)
    cache->size = 7;
    cache->n_items = 0;
    cache->items =
-      calloc(1, cache->size * sizeof(struct brw_cache_item));
+      calloc(1, cache->size * sizeof(struct brw_cache_item *));
 
    cache->bo = drm_intel_bo_alloc(intel->bufmgr,
                                  "program cache",
@@ -343,6 +344,8 @@ brw_init_caches(struct brw_context *brw)
 
    cache->aux_compare[BRW_VS_PROG] = brw_vs_prog_data_compare;
    cache->aux_compare[BRW_WM_PROG] = brw_wm_prog_data_compare;
+   cache->aux_free[BRW_VS_PROG] = brw_vs_prog_data_free;
+   cache->aux_free[BRW_WM_PROG] = brw_wm_prog_data_free;
 }
 
 static void
@@ -357,6 +360,10 @@ brw_clear_cache(struct brw_context *brw, struct brw_cache *cache)
    for (i = 0; i < cache->size; i++) {
       for (c = cache->items[i]; c; c = next) {
         next = c->next;
+         if (cache->aux_free[c->cache_id]) {
+            const void *item_aux = c->key + c->key_size;
+            cache->aux_free[c->cache_id](item_aux);
+         }
         free((void *)c->key);
         free(c);
       }