diff options
author | ghelmer <ghelmer@FreeBSD.org> | 2012-01-05 23:08:11 +0000 |
---|---|---|
committer | ghelmer <ghelmer@FreeBSD.org> | 2012-01-05 23:08:11 +0000 |
commit | 47061c1fd8043a856647feaf17cc6ec450d31875 (patch) | |
tree | 131dfb724244ed35b1e98cd1482b3115b721ab53 /usr.bin | |
parent | cb04d194f43ed42f8c7a481a92e85c086db45df9 (diff) | |
download | FreeBSD-src-47061c1fd8043a856647feaf17cc6ec450d31875.zip FreeBSD-src-47061c1fd8043a856647feaf17cc6ec450d31875.tar.gz |
Fix a memory leak in addgroup() by ensuring the allocated memory
is freed if an error occurs.
PR: bin/161510
MFC after: 4 weeks
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/newgrp/newgrp.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/usr.bin/newgrp/newgrp.c b/usr.bin/newgrp/newgrp.c index 5381b15..751e8be 100644 --- a/usr.bin/newgrp/newgrp.c +++ b/usr.bin/newgrp/newgrp.c @@ -190,7 +190,7 @@ addgroup(const char *grpname) err(1, "malloc"); if ((ngrps = getgroups(ngrps_max, (gid_t *)grps)) < 0) { warn("getgroups"); - return; + goto end; } /* Remove requested gid from supp. list if it exists. */ @@ -204,7 +204,7 @@ addgroup(const char *grpname) if (setgroups(ngrps, (const gid_t *)grps) < 0) { PRIV_END; warn("setgroups"); - return; + goto end; } PRIV_END; } @@ -213,7 +213,7 @@ addgroup(const char *grpname) if (setgid(grp->gr_gid)) { PRIV_END; warn("setgid"); - return; + goto end; } PRIV_END; grps[0] = grp->gr_gid; @@ -228,12 +228,12 @@ addgroup(const char *grpname) if (setgroups(ngrps, (const gid_t *)grps)) { PRIV_END; warn("setgroups"); - return; + goto end; } PRIV_END; } } - +end: free(grps); } |