From c3804ab00e95b6b9e330275cb4ff1c10f8af5531 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 2 Jan 2023 00:52:23 +0100 Subject: fsys_get_children: Fix memleak on error --- libdiskfs/fsys-get-children.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'libdiskfs/fsys-get-children.c') diff --git a/libdiskfs/fsys-get-children.c b/libdiskfs/fsys-get-children.c index 1c20f1ee..d9be535a 100644 --- a/libdiskfs/fsys-get-children.c +++ b/libdiskfs/fsys-get-children.c @@ -40,7 +40,7 @@ diskfs_S_fsys_get_children (struct diskfs_control *fsys, mach_msg_type_number_t *controlsCnt) { error_t err; - char *n = NULL; + char *n = NULL, *orig_names = *names; size_t n_len = 0; mach_port_t *c; size_t c_count; @@ -62,7 +62,11 @@ diskfs_S_fsys_get_children (struct diskfs_control *fsys, (char **) controls, controlsCnt); c = NULL; /* c was freed by iohelp_return_malloced_buffer. */ if (err) - goto errout; + { + if (*names != *orig_names) + munmap (*names, n_len); + goto errout; + } *controlsPoly = MACH_MSG_TYPE_MOVE_SEND; *controlsCnt = c_count; -- cgit v1.2.3