git: 09f29b03ddf8 - main - sesutil: plug memory leaks
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 09 Feb 2023 21:44:04 UTC
The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=09f29b03ddf857a366f338145693b5449e6ca5de commit 09f29b03ddf857a366f338145693b5449e6ca5de Author: Alan Somers <asomers@FreeBSD.org> AuthorDate: 2022-01-19 21:57:27 +0000 Commit: Alan Somers <asomers@FreeBSD.org> CommitDate: 2023-02-09 21:43:17 +0000 sesutil: plug memory leaks MFC after: 1 week Sponsored by: Axcient Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D33955 --- usr.sbin/sesutil/sesutil.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usr.sbin/sesutil/sesutil.c b/usr.sbin/sesutil/sesutil.c index b11f02177c62..989216690edf 100644 --- a/usr.sbin/sesutil/sesutil.c +++ b/usr.sbin/sesutil/sesutil.c @@ -484,7 +484,6 @@ objmap(int argc, char **argv __unused) memset(&e_desc, 0, sizeof(e_desc)); e_desc.elm_idx = e_ptr[j].elm_idx; e_desc.elm_desc_len = UINT16_MAX; - /* XXX memory leak! */ e_desc.elm_desc_str = calloc(UINT16_MAX, sizeof(char)); if (e_desc.elm_desc_str == NULL) { close(fd); @@ -526,6 +525,7 @@ objmap(int argc, char **argv __unused) } print_extra_status(e_ptr[j].elm_type, e_status.cstat, PRINT_STYLE_DASHED); xo_close_instance("elements"); + free(e_desc.elm_desc_str); free(e_devname.elm_devnames); } xo_close_list("elements"); @@ -618,7 +618,7 @@ static void show_device(int fd, int elm_idx, encioc_elm_status_t e_status, encioc_elm_desc_t e_desc) { encioc_elm_devnames_t e_devname; - char *model, *serial; + char *model = NULL, *serial = NULL; off_t size; /* Get the device name(s) of the element */ @@ -635,8 +635,6 @@ show_device(int fd, int elm_idx, encioc_elm_status_t e_status, encioc_elm_desc_t (caddr_t) &e_devname) < 0) { /* We don't care if this fails */ e_devname.elm_devnames[0] = '\0'; - model = NULL; - serial = NULL; size = -1; } else { skip_pass_devices(e_devname.elm_devnames, 128); @@ -661,6 +659,8 @@ show_device(int fd, int elm_idx, encioc_elm_status_t e_status, encioc_elm_desc_t print_extra_status(ELMTYP_ARRAY_DEV, e_status.cstat, PRINT_STYLE_CSV); xo_emit("\n"); xo_close_instance("elements"); + free(serial); + free(model); free(e_devname.elm_devnames); } @@ -853,6 +853,7 @@ show(int argc, char **argv __unused) */ break; } + free(e_desc.elm_desc_str); } if (prev_type != (elm_type_t)-1 && prev_type != ELMTYP_DEVICE && prev_type != ELMTYP_ARRAY_DEV)