ref: ddf993570ac55a371f5d1fe724eaaa43180bfeed
parent: 9b49a47d09b75649596e7c63df4ec59060a1bdd0
author: Michael Forney <mforney@mforney.org>
date: Tue Apr 4 14:26:33 EDT 2023
user: fix memory leaks when parseusers fails
--- a/user.c
+++ b/user.c
@@ -186,8 +186,10 @@
continue;
getfield(&p, ':'); /* skip id */
getfield(&p, ':'); /* skip name */
- if((f = getfield(&p, ':')) == nil)
- return Esyntax;
+ if((f = getfield(&p, ':')) == nil){
+ err = Esyntax;
+ goto Error;
+ }
if(f[0] != '\0'){
u = nil;
for(j = 0; j < nusers; j++)
@@ -200,8 +202,10 @@
}
users[i].lead = u->id;
}
- if((f = getfield(&p, ':')) == nil)
- return Esyntax;
+ if((f = getfield(&p, ':')) == nil){
+ err = Esyntax;
+ goto Error;
+ }
grp = nil;
ngrp = 0;
while((m = getfield(&f, ',')) != nil){
@@ -213,10 +217,12 @@
u = &users[j];
if(u == nil){
fprint(fd, "/adm/users:%d: user %s does not exist\n", lnum, m);
+ free(grp);
err = Enouser;
goto Error;
}
if((g = realloc(grp, (ngrp+1)*sizeof(int))) == nil){
+ free(grp);
err = Enomem;
goto Error;
}