Skip to content

Commit 3e3b374

Browse files
lib/gshadow.c: fgetsgent(): Don't use static variables
Reported-by: Chris Hofstaedtler <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
1 parent decf456 commit 3e3b374

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/gshadow.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,23 @@ void endsgent (void)
140140
/*@observer@*//*@null@*/struct sgrp *
141141
fgetsgent(/*@null@*/FILE *fp)
142142
{
143-
static size_t buflen = 0;
144-
static char *buf = NULL;
143+
char *buf = NULL;
144+
size_t buflen = 0;
145+
struct sgrp *sg;
145146

146-
if (NULL == fp) {
147+
if (NULL == fp)
147148
return NULL;
148-
}
149149

150150
if (getline(&buf, &buflen, fp) == -1)
151151
return NULL;
152152
if (stpsep(buf, "\n") == NULL)
153153
return NULL;
154154

155-
return (sgetsgent (buf));
155+
sg = sgetsgent(buf);
156+
157+
free(buf);
158+
159+
return sg;
156160
}
157161

158162

0 commit comments

Comments
 (0)