mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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
This commit is contained in:
parent
5eff94ee56
commit
94c1ff89ad
1 changed files with 6 additions and 5 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue