summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2015-12-10 07:04:36 +0000
committerngie <ngie@FreeBSD.org>2015-12-10 07:04:36 +0000
commitfcd41d4f012a952ccf988893a653da2b39eaa260 (patch)
treeb5e5cb16acdd44a8ed05844e3c5a5fcd757d07cb /sbin
parent60361f83a82a106e15374eb64338c25112f46945 (diff)
downloadFreeBSD-src-fcd41d4f012a952ccf988893a653da2b39eaa260.zip
FreeBSD-src-fcd41d4f012a952ccf988893a653da2b39eaa260.tar.gz
Don't leak rsector/sector in mp_label(..)
Use calloc instead of malloc + memset(.., 0, ..) when allocating sector Differential Revision: https://reviews.freebsd.org/D4450 MFC after: 1 week Reported by: cppcheck Reviewed by: mav Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'sbin')
-rw-r--r--sbin/geom/class/multipath/geom_multipath.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sbin/geom/class/multipath/geom_multipath.c b/sbin/geom/class/multipath/geom_multipath.c
index cdf35d0..5743911 100644
--- a/sbin/geom/class/multipath/geom_multipath.c
+++ b/sbin/geom/class/multipath/geom_multipath.c
@@ -221,17 +221,15 @@ mp_label(struct gctl_req *req)
/*
* Allocate a sector to write as metadata.
*/
- sector = malloc(secsize);
+ sector = calloc(1, secsize);
if (sector == NULL) {
gctl_error(req, "unable to allocate metadata buffer");
return;
}
- memset(sector, 0, secsize);
rsector = malloc(secsize);
if (rsector == NULL) {
- free(sector);
gctl_error(req, "unable to allocate metadata buffer");
- return;
+ goto done;
}
/*
@@ -246,7 +244,7 @@ mp_label(struct gctl_req *req)
error = g_metadata_store(name, sector, secsize);
if (error != 0) {
gctl_error(req, "cannot store metadata on %s: %s.", name, strerror(error));
- return;
+ goto done;
}
/*
@@ -274,6 +272,9 @@ mp_label(struct gctl_req *req)
name2, name);
}
}
+done:
+ free(rsector);
+ free(sector);
}
OpenPOWER on IntegriCloud