Skip to content

wdc-nvme: fix resource leak in wdc_enc_get_log()#3534

Closed
sahmed-ibm wants to merge 1 commit into
linux-nvme:masterfrom
sahmed-ibm:fix-wdc-nvme-resource-leak-output_fd
Closed

wdc-nvme: fix resource leak in wdc_enc_get_log()#3534
sahmed-ibm wants to merge 1 commit into
linux-nvme:masterfrom
sahmed-ibm:fix-wdc-nvme-resource-leak-output_fd

Conversation

@sahmed-ibm

Copy link
Copy Markdown
Contributor

The wdc_enc_get_log() function opens a file stream for writing when the user provides an output file path. The @output_fd pointer was declared as a plain FILE pointer with no cleanup mechanism, and no explicit fclose() call exists on any return path through the function.

Because FILE streams buffer writes in userspace, failing to close the stream means buffered data is never flushed to disk. The output file will silently contain truncated or missing log data, and the underlying file descriptor is leaked for the lifetime of the process.

Fix this by introducing a non-owning @fd pointer for passing to the helper functions. Declare @output_fd with __cleanup_file so it is automatically closed when the function returns. Assign @output_fd only when a real file is opened so that stdout is never passed to fclose().

Signed-off-by: Sarah Ahmed sarah.ahmed@ibm.com

The wdc_enc_get_log() function opens a file stream for writing
when the user provides an output file path. The @output_fd
pointer was declared as a plain FILE pointer with no cleanup
mechanism, and no explicit fclose() call exists on any return
path through the function.

Because FILE streams buffer writes in userspace, failing to
close the stream means buffered data is never flushed to disk.
The output file will silently contain truncated or missing log
data, and the underlying file descriptor is leaked for the
lifetime of the process.

Fix this by introducing a non-owning @fd pointer for passing to the helper
functions. Declare @output_fd with __cleanup_file so it is
automatically closed when the function returns. Assign @output_fd
only when a real file is opened so that stdout is never passed
to fclose().

Signed-off-by: Sarah Ahmed <sarah.ahmed@ibm.com>
@sahmed-ibm sahmed-ibm closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant