Fix a memory leak in addgroup() by ensuring the allocated memory
is freed if an error occurs. PR: bin/161510 MFC after: 4 weeks
This commit is contained in:
parent
074db536b3
commit
532b72687e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=229668
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user