Plug various resources leak

While here fix a test logic

Reported by:	coverity
CID:		1332096, 1332097, 1332098, 1332099, 1332100, 1332101, 1332102
MFC after:	1 week
This commit is contained in:
bapt 2016-04-20 21:32:34 +00:00
parent 7cc967f0e0
commit 40ccde4c2e

View File

@ -139,15 +139,19 @@ show_adapter(int ac, char **av)
if (sas0 == NULL) { if (sas0 == NULL) {
error = errno; error = errno;
warn("Error retrieving SAS IO Unit page %d", IOCStatus); warn("Error retrieving SAS IO Unit page %d", IOCStatus);
free(sas0);
close(fd);
return (error); return (error);
} }
sas1 = mps_read_extended_config_page(fd, sas1 = mps_read_extended_config_page(fd,
MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT, MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
MPI2_SASIOUNITPAGE1_PAGEVERSION, 1, 0, &IOCStatus); MPI2_SASIOUNITPAGE1_PAGEVERSION, 1, 0, &IOCStatus);
if (sas0 == NULL) { if (sas1 == NULL) {
error = errno; error = errno;
warn("Error retrieving SAS IO Unit page %d", IOCStatus); warn("Error retrieving SAS IO Unit page %d", IOCStatus);
free(sas0);
close(fd);
return (error); return (error);
} }
printf("\n"); printf("\n");
@ -266,12 +270,14 @@ show_adapters(int ac, char **av)
error = errno; error = errno;
warn("Failed to get controller info"); warn("Failed to get controller info");
close(fd); close(fd);
free(facts);
return (error); return (error);
} }
if (man0->Header.PageLength < sizeof(*man0) / 4) { if (man0->Header.PageLength < sizeof(*man0) / 4) {
warnx("Invalid controller info"); warnx("Invalid controller info");
close(fd); close(fd);
free(man0); free(man0);
free(facts);
return (EINVAL); return (EINVAL);
} }
printf("/dev/mp%s%d\t%16s %16s %08x\n", printf("/dev/mp%s%d\t%16s %16s %08x\n",
@ -476,6 +482,7 @@ show_devices(int ac, char **av)
break; break;
error = errno; error = errno;
warn("Error retrieving device page"); warn("Error retrieving device page");
close(fd);
return (error); return (error);
} }
handle = device->DevHandle; handle = device->DevHandle;
@ -515,6 +522,8 @@ show_devices(int ac, char **av)
error = errno; error = errno;
warn("Error retrieving expander page 1: 0x%x", warn("Error retrieving expander page 1: 0x%x",
IOCStatus); IOCStatus);
close(fd);
free(device);
return (error); return (error);
} }
speed = " "; speed = " ";
@ -579,6 +588,7 @@ show_enclosures(int ac, char **av)
break; break;
error = errno; error = errno;
warn("Error retrieving enclosure page"); warn("Error retrieving enclosure page");
close(fd);
return (error); return (error);
} }
type = get_enc_type(enc->Flags, &issep); type = get_enc_type(enc->Flags, &issep);
@ -629,6 +639,7 @@ show_expanders(int ac, char **av)
break; break;
error = errno; error = errno;
warn("Error retrieving expander page 0"); warn("Error retrieving expander page 0");
close(fd);
return (error); return (error);
} }
@ -766,6 +777,7 @@ show_cfgpage(int ac, char **av)
printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr); printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr);
hexdump(data, len, NULL, HD_REVERSED | 4); hexdump(data, len, NULL, HD_REVERSED | 4);
free(data); free(data);
close(fd);
return (0); return (0);
} }