diff options
author | mjg <mjg@FreeBSD.org> | 2014-10-21 23:08:46 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2014-10-21 23:08:46 +0000 |
commit | 4386bf043d1b3107a4a480ad90128e1246fdb07c (patch) | |
tree | 806954c654a0a29f158c5e1a3760529fba986938 /sys/i386 | |
parent | af449b2b721af52b6671674857bca812e30f3f8a (diff) | |
download | FreeBSD-src-4386bf043d1b3107a4a480ad90128e1246fdb07c.zip FreeBSD-src-4386bf043d1b3107a4a480ad90128e1246fdb07c.tar.gz |
Eliminate unnecessary memory allocation in sys_getgroups and its ibcs2 counterpart.
Diffstat (limited to 'sys/i386')
-rw-r--r-- | sys/i386/ibcs2/ibcs2_misc.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index 0eeb6de..42bc4b7 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -659,33 +659,28 @@ ibcs2_getgroups(td, uap) struct thread *td; struct ibcs2_getgroups_args *uap; { + struct ucred *cred; ibcs2_gid_t *iset; - gid_t *gp; u_int i, ngrp; int error; - if (uap->gidsetsize < td->td_ucred->cr_ngroups) { - if (uap->gidsetsize == 0) - ngrp = 0; - else - return (EINVAL); - } else - ngrp = td->td_ucred->cr_ngroups; - gp = malloc(ngrp * sizeof(*gp), M_TEMP, M_WAITOK); - error = kern_getgroups(td, &ngrp, gp); - if (error) + cred = td->td_ucred; + ngrp = cred->cr_ngroups; + + if (uap->gidsetsize == 0) { + error = 0; goto out; - if (uap->gidsetsize > 0) { - iset = malloc(ngrp * sizeof(*iset), M_TEMP, M_WAITOK); - for (i = 0; i < ngrp; i++) - iset[i] = (ibcs2_gid_t)gp[i]; - error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t)); - free(iset, M_TEMP); } - if (error == 0) - td->td_retval[0] = ngrp; + if (uap->gidsetsize < ngrp) + return (EINVAL); + + iset = malloc(ngrp * sizeof(*iset), M_TEMP, M_WAITOK); + for (i = 0; i < ngrp; i++) + iset[i] = (ibcs2_gid_t)cred->cr_groups[i]; + error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t)); + free(iset, M_TEMP); out: - free(gp, M_TEMP); + td->td_retval[0] = ngrp; return (error); } |