aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/mfiutil/mfi_flash.c
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2011-06-09 19:52:28 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2011-06-09 19:52:28 +0000
commit375c46563c58c3ff17de2ae0fc49118110f7918d (patch)
tree4c98a9f41402a583d5d4eba562ecba6eebcb2916 /usr.sbin/mfiutil/mfi_flash.c
parentb9856e92ac62c58bac9d0fcbba288ac3c024dc59 (diff)
downloadsrc-375c46563c58c3ff17de2ae0fc49118110f7918d.tar.gz
src-375c46563c58c3ff17de2ae0fc49118110f7918d.zip
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
Notes
Notes: svn path=/head/; revision=222899
Diffstat (limited to 'usr.sbin/mfiutil/mfi_flash.c')
-rw-r--r--usr.sbin/mfiutil/mfi_flash.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/usr.sbin/mfiutil/mfi_flash.c b/usr.sbin/mfiutil/mfi_flash.c
index 4039beb323cc..6d07cb0651e3 100644
--- a/usr.sbin/mfiutil/mfi_flash.c
+++ b/usr.sbin/mfiutil/mfi_flash.c
@@ -136,21 +136,25 @@ flash_adapter(int ac, char **av)
return (error);
}
+ buf = NULL;
+ fd = -1;
+
if (fstat(flash, &sb) < 0) {
error = errno;
warn("fstat(%s)", av[1]);
- return (error);
+ goto error;
}
if (sb.st_size % 1024 != 0 || sb.st_size > 0x7fffffff) {
warnx("Invalid flash file size");
- return (EINVAL);
+ error = EINVAL;
+ goto error;
}
fd = mfi_open(mfi_unit);
if (fd < 0) {
error = errno;
warn("mfi_open");
- return (error);
+ goto error;
}
/* First, ask the firmware to allocate space for the flash file. */
@@ -158,14 +162,16 @@ flash_adapter(int ac, char **av)
mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_OPEN, NULL, 0, mbox, 4, &status);
if (status != MFI_STAT_OK) {
warnx("Failed to alloc flash memory: %s", mfi_status(status));
- return (EIO);
+ error = EIO;
+ goto error;
}
/* Upload the file 64k at a time. */
buf = malloc(FLASH_BUF_SIZE);
if (buf == NULL) {
warnx("malloc failed");
- return (ENOMEM);
+ error = ENOMEM;
+ goto error;
}
offset = 0;
while (sb.st_size > 0) {
@@ -174,7 +180,8 @@ flash_adapter(int ac, char **av)
warnx("Bad read from flash file");
mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_CLOSE, NULL, 0,
NULL, 0, NULL);
- return (ENXIO);
+ error = ENXIO;
+ goto error;
}
mbox_store_word(mbox, offset);
@@ -184,12 +191,12 @@ flash_adapter(int ac, char **av)
warnx("Flash download failed: %s", mfi_status(status));
mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_CLOSE, NULL, 0,
NULL, 0, NULL);
- return (ENXIO);
+ error = ENXIO;
+ goto error;
}
sb.st_size -= nread;
offset += nread;
}
- close(flash);
/* Kick off the flash. */
printf("WARNING: Firmware flash in progress, do not reboot machine... ");
@@ -198,12 +205,17 @@ flash_adapter(int ac, char **av)
NULL, 0, &status);
if (status != MFI_STAT_OK) {
printf("failed:\n\t%s\n", mfi_status(status));
- return (ENXIO);
+ error = ENXIO;
+ goto error;
}
printf("finished\n");
error = display_pending_firmware(fd);
- close(fd);
+error:
+ free(buf);
+ if (fd >= 0)
+ close(fd);
+ close(flash);
return (error);
}