From 07b1a989387e83f3b007852b559a088efa226576 Mon Sep 17 00:00:00 2001 From: trixirt Date: Thu, 3 Sep 2020 16:25:58 -0700 Subject: [PATCH] Improve malloc error handling in xfpga_fpgaOpen (#76) The openclose open_06 test simulated malloc failures show that malloc failures in wsid_tracker_init need to be handled. So check the returns and cleanup on failures. Signed-off-by: Tom Rix --- plugins/xfpga/open.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/xfpga/open.c b/plugins/xfpga/open.c index 9bc1a5cd7eb6..85549797d612 100644 --- a/plugins/xfpga/open.c +++ b/plugins/xfpga/open.c @@ -87,9 +87,17 @@ xfpga_fpgaOpen(fpga_token token, fpga_handle *handle, int flags) // Init MMIO table _handle->mmio_root = wsid_tracker_init(4); + if (NULL == _handle->mmio_root) { + result = FPGA_NO_MEMORY; + goto out_free1; + } // Init workspace table _handle->wsid_root = wsid_tracker_init(16384); + if (NULL == _handle->wsid_root) { + result = FPGA_NO_MEMORY; + goto out_free2; + } // Init metric enum _handle->metric_enum_status = false; @@ -151,7 +159,9 @@ xfpga_fpgaOpen(fpga_token token, fpga_handle *handle, int flags) out_free: wsid_tracker_cleanup(_handle->wsid_root, NULL); +out_free2: wsid_tracker_cleanup(_handle->mmio_root, NULL); +out_free1: free(_handle); if (-1 != fddev) {