diff options
author | bz <bz@FreeBSD.org> | 2011-06-09 19:52:28 +0000 |
---|---|---|
committer | bz <bz@FreeBSD.org> | 2011-06-09 19:52:28 +0000 |
commit | 7c90f6cd22233b1b4a920e14e037a09b3f7c936e (patch) | |
tree | 4c98a9f41402a583d5d4eba562ecba6eebcb2916 /usr.sbin/mfiutil/mfi_evt.c | |
parent | d90b849335985b5cc6970fd22a6bd6af1c21d6e5 (diff) | |
download | FreeBSD-src-7c90f6cd22233b1b4a920e14e037a09b3f7c936e.zip FreeBSD-src-7c90f6cd22233b1b4a920e14e037a09b3f7c936e.tar.gz |
Contrary to when returning in all-good cases at the end of functions we
did not free memory (1) or close the file descriptor (2) in error cases.
Reported by: Mark Johnston (1)
Reported by: attilio (2)
Reviewed by: jhb
Sponsored by: Sandvine Incorporated
MFC after: 1 week
Diffstat (limited to 'usr.sbin/mfiutil/mfi_evt.c')
-rw-r--r-- | usr.sbin/mfiutil/mfi_evt.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/usr.sbin/mfiutil/mfi_evt.c b/usr.sbin/mfiutil/mfi_evt.c index a8a8775..336fbd3 100644 --- a/usr.sbin/mfiutil/mfi_evt.c +++ b/usr.sbin/mfiutil/mfi_evt.c @@ -83,6 +83,7 @@ show_logstate(int ac, char **av) if (mfi_event_get_info(fd, &info, NULL) < 0) { error = errno; warn("Failed to get event log info"); + close(fd); return (error); } @@ -550,6 +551,7 @@ show_events(int ac, char **av) if (mfi_event_get_info(fd, &info, NULL) < 0) { error = errno; warn("Failed to get event log info"); + close(fd); return (error); } @@ -570,6 +572,7 @@ show_events(int ac, char **av) if (parse_class(optarg, &filter.members.evt_class) < 0) { error = errno; warn("Error parsing event class"); + close(fd); return (error); } break; @@ -577,6 +580,7 @@ show_events(int ac, char **av) if (parse_locale(optarg, &filter.members.locale) < 0) { error = errno; warn("Error parsing event locale"); + close(fd); return (error); } break; @@ -584,6 +588,7 @@ show_events(int ac, char **av) val = strtol(optarg, &cp, 0); if (*cp != '\0' || val <= 0) { warnx("Invalid event count"); + close(fd); return (EINVAL); } num_events = val; @@ -593,6 +598,7 @@ show_events(int ac, char **av) break; case '?': default: + close(fd); return (EINVAL); } } @@ -604,28 +610,33 @@ show_events(int ac, char **av) (num_events - 1); if (size > getpagesize()) { warnx("Event count is too high"); + close(fd); return (EINVAL); } /* Handle optional start and stop sequence numbers. */ if (ac > 2) { warnx("show events: extra arguments"); + close(fd); return (EINVAL); } if (ac > 0 && parse_seq(&info, av[0], &start) < 0) { error = errno; warn("Error parsing starting sequence number"); + close(fd); return (error); } if (ac > 1 && parse_seq(&info, av[1], &stop) < 0) { error = errno; warn("Error parsing ending sequence number"); + close(fd); return (error); } list = malloc(size); if (list == NULL) { warnx("malloc failed"); + close(fd); return (ENOMEM); } for (seq = start;;) { @@ -633,6 +644,8 @@ show_events(int ac, char **av) &status) < 0) { error = errno; warn("Failed to fetch events"); + free(list); + close(fd); return (error); } if (status == MFI_STAT_NOT_FOUND) { @@ -642,6 +655,8 @@ show_events(int ac, char **av) } if (status != MFI_STAT_OK) { warnx("Error fetching events: %s", mfi_status(status)); + free(list); + close(fd); return (EIO); } |