BTW, getline(3) says we are responsible for free(3)ing the buffer on
error.
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
struct sgrp *
fgetsgent(FILE *fp)
{
- static size_t buflen = 0;
- static char *buf = NULL;
+ char *buf;
+ size_t buflen;
+ struct sgrp *sg;
if (NULL == fp) {
return NULL;
}
+ buf = NULL;
+ buflen = 0;
if (getline(&buf, &buflen, fp) == -1)
- return NULL;
+ goto fail;
if (stpsep(buf, "\n") == NULL)
- return NULL;
+ goto fail;
+
+ sg = sgetsgent(buf);
- return sgetsgent(buf);
+ free(buf);
+ return sg;
+fail:
+ free(buf);
+ return NULL;
}
#endif