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
@ -190,7 +190,7 @@ addgroup(const char *grpname)
|
|||||||
err(1, "malloc");
|
err(1, "malloc");
|
||||||
if ((ngrps = getgroups(ngrps_max, (gid_t *)grps)) < 0) {
|
if ((ngrps = getgroups(ngrps_max, (gid_t *)grps)) < 0) {
|
||||||
warn("getgroups");
|
warn("getgroups");
|
||||||
return;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove requested gid from supp. list if it exists. */
|
/* 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) {
|
if (setgroups(ngrps, (const gid_t *)grps) < 0) {
|
||||||
PRIV_END;
|
PRIV_END;
|
||||||
warn("setgroups");
|
warn("setgroups");
|
||||||
return;
|
goto end;
|
||||||
}
|
}
|
||||||
PRIV_END;
|
PRIV_END;
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ addgroup(const char *grpname)
|
|||||||
if (setgid(grp->gr_gid)) {
|
if (setgid(grp->gr_gid)) {
|
||||||
PRIV_END;
|
PRIV_END;
|
||||||
warn("setgid");
|
warn("setgid");
|
||||||
return;
|
goto end;
|
||||||
}
|
}
|
||||||
PRIV_END;
|
PRIV_END;
|
||||||
grps[0] = grp->gr_gid;
|
grps[0] = grp->gr_gid;
|
||||||
@ -228,12 +228,12 @@ addgroup(const char *grpname)
|
|||||||
if (setgroups(ngrps, (const gid_t *)grps)) {
|
if (setgroups(ngrps, (const gid_t *)grps)) {
|
||||||
PRIV_END;
|
PRIV_END;
|
||||||
warn("setgroups");
|
warn("setgroups");
|
||||||
return;
|
goto end;
|
||||||
}
|
}
|
||||||
PRIV_END;
|
PRIV_END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
end:
|
||||||
free(grps);
|
free(grps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user