intel: tools: aubwrite: fix invalid frees on finish
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Wed, 18 Jul 2018 16:39:19 +0000 (17:39 +0100)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 19 Jul 2018 19:11:56 +0000 (20:11 +0100)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
src/intel/tools/aub_write.c

index 07f38b97d4efbbbac2fc010899cd2b7b86fa05b6..6fb99feb00532952529993e31801e30ed24a37d5 100644 (file)
@@ -255,11 +255,16 @@ align_u32(uint32_t v, uint32_t a)
 }
 
 static void
-aub_ppgtt_table_finish(struct aub_ppgtt_table *table)
+aub_ppgtt_table_finish(struct aub_ppgtt_table *table, int level)
 {
+   if (level == 1)
+      return;
+
    for (unsigned i = 0; i < ARRAY_SIZE(table->subtables); i++) {
-      aub_ppgtt_table_finish(table->subtables[i]);
-      free(table->subtables[i]);
+      if (table->subtables[i]) {
+         aub_ppgtt_table_finish(table->subtables[i], level - 1);
+         free(table->subtables[i]);
+      }
    }
 }
 
@@ -280,7 +285,7 @@ aub_file_init(struct aub_file *aub, FILE *file, uint16_t pci_id)
 void
 aub_file_finish(struct aub_file *aub)
 {
-   aub_ppgtt_table_finish(&aub->pml4);
+   aub_ppgtt_table_finish(&aub->pml4, 4);
    fclose(aub->file);
 }