misc/172553: Memory leak and allocator sizeof operand mismatch in umount
Erik Cederstrand
erik at cederstrand.dk
Tue Oct 9 22:30:29 UTC 2012
>Number: 172553
>Category: misc
>Synopsis: Memory leak and allocator sizeof operand mismatch in umount
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Oct 09 22:30:28 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Erik Cederstrand
>Release: CURRENT
>Organization:
>Environment:
>Description:
This patch fixes several sources of memory leaks and an allocator sizeof operand mismatch in umount.
The fixes are based on the reports generated by Clang Static Analyzer: http://scan.freebsd.your.org/freebsd-head/sbin.umount/2012-10-03-amd64/
The attached patch fixes all analyzer warnings un umount.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
Index: head/sbin/umount/umount.c
===================================================================
--- head/sbin/umount/umount.c (revision 241370)
+++ head/sbin/umount/umount.c (working copy)
@@ -359,8 +359,11 @@
do_rpc = 1;
}
- if (!namematch(ai))
+ if (!namematch(ai)) {
+ if (orignfsdirname != NULL)
+ free(orignfsdirname);
return (1);
+ }
/* First try to unmount using the file system ID. */
snprintf(fsidbuf, sizeof(fsidbuf), "FSID:%d:%d", sfs->f_fsid.val[0],
sfs->f_fsid.val[1]);
@@ -369,13 +372,18 @@
if (errno != ENOENT || sfs->f_fsid.val[0] != 0 ||
sfs->f_fsid.val[1] != 0)
warn("unmount of %s failed", sfs->f_mntonname);
- if (errno != ENOENT)
+ if (errno != ENOENT) {
+ if (orignfsdirname != NULL)
+ free(orignfsdirname);
return (1);
+ }
/* Compatibility for old kernels. */
if (sfs->f_fsid.val[0] != 0 || sfs->f_fsid.val[1] != 0)
warnx("retrying using path instead of file system ID");
if (unmount(sfs->f_mntonname, fflag) != 0) {
warn("unmount of %s failed", sfs->f_mntonname);
+ if (orignfsdirname != NULL)
+ free(orignfsdirname);
return (1);
}
}
@@ -393,6 +401,8 @@
if (clp == NULL) {
warnx("%s: %s", hostp,
clnt_spcreateerror("MOUNTPROG"));
+ if (orignfsdirname != NULL)
+ free(orignfsdirname);
return (1);
}
clp->cl_auth = authsys_create_default();
@@ -403,6 +413,8 @@
if (clnt_stat != RPC_SUCCESS) {
warnx("%s: %s", hostp,
clnt_sperror(clp, "RPCMNT_UMOUNT"));
+ if (orignfsdirname != NULL)
+ free(orignfsdirname);
return (1);
}
/*
@@ -415,10 +427,11 @@
hostp, nfsdirname);
free_mtab();
}
- free(orignfsdirname);
auth_destroy(clp->cl_auth);
clnt_destroy(clp);
}
+ if (orignfsdirname != NULL)
+ free(orignfsdirname);
return (0);
}
@@ -436,7 +449,7 @@
return (NULL);
}
if (mntcheck == NULL) {
- if ((mntcheck = calloc(mntsize + 1, sizeof(int))) == NULL)
+ if ((mntcheck = calloc(mntsize + 1, sizeof(char))) == NULL)
err(1, "calloc");
}
/*
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list