From 8f90b10b63065cb294215d16e547b3fd54e95c31 Mon Sep 17 00:00:00 2001 From: Sushma Venkatesh Reddy Date: Thu, 3 Apr 2025 19:05:23 +0000 Subject: [PATCH] intel/tools: Improve memory allocation failure handling in aubinator_error_decode_xe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure proper cleanup when memory allocation fails during HWCTX and VMA parsing in `read_xe_data_file`. This ensures graceful error handling by preventing potential memory leaks. Reviewed-by: José Roberto de Souza Part-of: --- src/intel/tools/aubinator_error_decode_xe.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/intel/tools/aubinator_error_decode_xe.c b/src/intel/tools/aubinator_error_decode_xe.c index 25a81d53473..c20ee81d201 100644 --- a/src/intel/tools/aubinator_error_decode_xe.c +++ b/src/intel/tools/aubinator_error_decode_xe.c @@ -247,7 +247,8 @@ read_xe_data_file(FILE *file, vm_entry_data = calloc(1, vm_entry_len); if (!vm_entry_data) { printf("Out of memory to allocate a buffer to store content of HWCTX\n"); - break; + printf("Aborting decode process due to insufficient memory\n"); + goto cleanup; } if (is_hw_ctx) @@ -282,7 +283,8 @@ read_xe_data_file(FILE *file, vm_entry_data = calloc(1, vm_entry_len); if (!vm_entry_data) { printf("Out of memory to allocate a buffer to store content of VMA 0x%" PRIx64 "\n", address); - break; + printf("Aborting decode process due to insufficient memory\n"); + goto cleanup; } if (!error_decode_xe_vm_append(&xe_vm, address, vm_entry_len, vm_entry_data)) { printf("xe_vm_append() failed for VMA 0x%" PRIx64 "\n", address); @@ -349,6 +351,8 @@ read_xe_data_file(FILE *file, } intel_batch_decode_ctx_finish(&batch_ctx); + +cleanup: intel_spec_destroy(spec); free(batch_buffers.addrs); free(line);