From: Martin George Date: Tue, 1 Mar 2022 11:52:36 +0000 (+0530) Subject: nvme: fix segfault in nvme telemetry-log error handling X-Git-Tag: v2.0-rc5~7^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7e89f04968b563134f3750128b9465daa3b87e02;p=users%2Fsagi%2Fnvme-cli.git nvme: fix segfault in nvme telemetry-log error handling After the upgrade to libnvme, the nvme telemetry-log command segfaults for error scenarios as shown below: NVMe status: Invalid Log Page: The log page indicated is invalid(0x4009) Failed to acquire telemetry log 16393! Segmentation fault (core dumped) Freeing the telemetry log page header for error scenarios is already handled in the libnvme. So avoid freeing this again here, which led to this segfault. Signed-off-by: Martin George --- diff --git a/nvme.c b/nvme.c index 5e9e5cda..d707c18d 100644 --- a/nvme.c +++ b/nvme.c @@ -482,7 +482,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, fprintf(stderr, "Failed to open output file %s: %s!\n", cfg.file_name, strerror(errno)); err = output; - goto free_mem; + goto close_fd; } if (cfg.ctrl_init) @@ -526,10 +526,10 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, return -1; } + free(log); + close_output: close(output); -free_mem: - free(log); close_fd: close(fd); ret: