[Mesa-dev] [PATCH 2/2] intel: tools: dump: protect against multiple calls on destructor

Lionel Landwerlin lionel.g.landwerlin at intel.com
Fri Jul 20 10:24:59 UTC 2018


Because we LD_PRELOAD in front of the command line, which might
contain gdb, the fini destructor in intel_dump_gpu.c might be called
twice (once for the program we're tracing and once for gdb). This
change prevents a crash in gdb when the aub->file has already been
closed.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/tools/aub_write.c      |  5 ++++-
 src/intel/tools/intel_dump_gpu.c | 10 ++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/intel/tools/aub_write.c b/src/intel/tools/aub_write.c
index 6fb99feb005..c948a4852b0 100644
--- a/src/intel/tools/aub_write.c
+++ b/src/intel/tools/aub_write.c
@@ -286,7 +286,10 @@ void
 aub_file_finish(struct aub_file *aub)
 {
    aub_ppgtt_table_finish(&aub->pml4, 4);
-   fclose(aub->file);
+   if (aub->file) {
+      fclose(aub->file);
+      aub->file = NULL;
+   }
 }
 
 uint32_t
diff --git a/src/intel/tools/intel_dump_gpu.c b/src/intel/tools/intel_dump_gpu.c
index 1abe54147cf..c4082c207f0 100644
--- a/src/intel/tools/intel_dump_gpu.c
+++ b/src/intel/tools/intel_dump_gpu.c
@@ -538,7 +538,13 @@ ioctl_init_helper(int fd, unsigned long request, ...)
 static void __attribute__ ((destructor))
 fini(void)
 {
-   free(output_filename);
    aub_file_finish(&aub_file);
-   free(bos);
+   if (output_filename) {
+      free(output_filename);
+      output_filename = NULL;
+   }
+   if (bos) {
+      free(bos);
+      bos = NULL;
+   }
 }
-- 
2.18.0



More information about the mesa-dev mailing list