From cb0e18ea4cd9fccb993392ff77d16f62aedfaaad Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Thu, 6 Feb 2025 00:30:12 +0900 Subject: [PATCH] ocp: fix to free hwcomp log desc memory allocated Since the desc pointer used _cleanup_free_ only set NULL value. Signed-off-by: Tokunori Ikegami [wagi: free buffer on error in get_hwcomp_log_data] Signed-off-by: Daniel Wagner --- plugins/ocp/ocp-hardware-component-log.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index 3c6890af..e4a8e065 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -219,7 +219,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log) log->desc = calloc(1, args.len); if (!log->desc) { fprintf(stderr, "error: ocp: calloc: %s\n", strerror(errno)); - return -1; + return -errno; } args.log = log->desc, @@ -232,6 +232,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log) if (ret) { print_info_error("error: ocp: failed to get log page (hwcomp: %02X, ret: %d)\n", OCP_LID_HWCOMP, ret); + free(log->desc); return ret; } #endif /* HWCOMP_DUMMY */ @@ -241,12 +242,10 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log) static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list) { - _cleanup_free_ __u8 *desc = NULL; - int ret; nvme_print_flags_t fmt; struct hwcomp_log log = { - .desc = (struct hwcomp_desc *)desc, + .desc = NULL, }; ret = validate_output_format(nvme_cfg.output_format, &fmt); @@ -264,6 +263,8 @@ static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list) ocp_show_hwcomp_log(&log, id, list, fmt); + free(log.desc); + return 0; } -- 2.51.0