Skip to content

Commit

Permalink
Improve malloc error handling in xfpga_fpgaOpen (#76)
Browse files Browse the repository at this point in the history
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 <trix@redhat.com>
  • Loading branch information
trixirt committed Sep 3, 2020
1 parent 8eb328a commit 07b1a98
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugins/xfpga/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 07b1a98

Please sign in to comment.