diff options
author | Pedro F. Giffuni <pfg@FreeBSD.org> | 2015-02-05 22:54:31 +0000 |
---|---|---|
committer | Pedro F. Giffuni <pfg@FreeBSD.org> | 2015-02-05 22:54:31 +0000 |
commit | 5262b957d491c244f5a75668d4dff0ec764df490 (patch) | |
tree | 156b0f1ec93eda1d68183377860b560e787d1370 | |
parent | 94f0eafcd25c5e856f62c099c79fadcf7ae7cced (diff) | |
download | src-5262b957d491c244f5a75668d4dff0ec764df490.tar.gz src-5262b957d491c244f5a75668d4dff0ec764df490.zip |
getdiskbyname(): plug resource leak
Variable cq going out of scope leaks the storage it points to.
CID: 270511
Phabric: D1775
Reviewed by: imp
Obtained from: NetBSD (CVS rev. 1.34)
MFC after: 2 weeks
Notes
Notes:
svn path=/head/; revision=278300
-rw-r--r-- | lib/libc/gen/disklabel.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index bd15a47318e0..5c7aa96a9a0a 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -85,10 +85,13 @@ getdiskbyname(const char *name) cq++, cp++; *cq = '\0'; - if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0) - dp->d_flags |= D_REMOVABLE; - else if (cq && strcmp(cq, "simulated") == 0) - dp->d_flags |= D_RAMDISK; + if (cgetstr(buf, "ty", &cq) > 0) { + if (strcmp(cq, "removable") == 0) + dp->d_flags |= D_REMOVABLE; + else if (cq && strcmp(cq, "simulated") == 0) + dp->d_flags |= D_RAMDISK; + free(cq); + } if (cgetcap(buf, "sf", ':') != NULL) dp->d_flags |= D_BADSECT; @@ -100,9 +103,10 @@ getdiskbyname(const char *name) getnumdflt(dp->d_nsectors, "ns", 0); getnumdflt(dp->d_ncylinders, "nc", 0); - if (cgetstr(buf, "dt", &cq) > 0) + if (cgetstr(buf, "dt", &cq) > 0) { dp->d_type = gettype(cq, dktypenames); - else + free(cq); + } else getnumdflt(dp->d_type, "dt", 0); getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); @@ -140,8 +144,11 @@ getdiskbyname(const char *name) pp->p_frag = 8; } getnumdflt(pp->p_fstype, ptype, 0); - if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0) - pp->p_fstype = gettype(cq, fstypenames); + if (pp->p_fstype == 0) + if (cgetstr(buf, ptype, &cq) >= 0) { + pp->p_fstype = gettype(cq, fstypenames); + free(cq); + } max = p; } } @@ -155,5 +162,6 @@ getdiskbyname(const char *name) dp->d_magic = DISKMAGIC; dp->d_magic2 = DISKMAGIC; free(buf); + (void)cgetclose(); return (dp); } |