summaryrefslogtreecommitdiff
path: root/libc/inet/getnetent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-03-18 11:12:34 +0000
committerEric Andersen <andersen@codepoet.org>2004-03-18 11:12:34 +0000
commite32376aaed01ed44981386e348ac35b58da23495 (patch)
tree3626e95d9c5c905b74085288d6e83ff7bd8dfa78 /libc/inet/getnetent.c
parent38cd8e780fc6375117e8bc7db2eca17764779bba (diff)
Reduce memory used by static buffers and allocate that memory dynamicly
instead. Based on an initial patch from Tobias Anderberg, but reworked. I asked Tobias to look into doing something more like what is done in busybox, but that proved to be a pain. One possible concern is that these buffers will probably show up as memory leaks i.e. with valgrind. Perhaps we should add in an atexit call to free this memory right after we allocate it?
Diffstat (limited to 'libc/inet/getnetent.c')
-rw-r--r--libc/inet/getnetent.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libc/inet/getnetent.c b/libc/inet/getnetent.c
index 9ade1f6b2..8c22c0a00 100644
--- a/libc/inet/getnetent.c
+++ b/libc/inet/getnetent.c
@@ -37,7 +37,7 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
#define MAXALIASES 35
static const char NETDB[] = _PATH_NETWORKS;
static FILE *netf = NULL;
-static char line[BUFSIZ+1];
+static char *line = NULL;
static struct netent net;
static char *net_aliases[MAXALIASES];
@@ -90,6 +90,13 @@ struct netent * getnetent(void)
return (NULL);
}
again:
+
+ if (!line) {
+ line = malloc(BUFSIZ + 1);
+ if (!line)
+ abort();
+ }
+
p = fgets(line, BUFSIZ, netf);
if (p == NULL) {
UNLOCK;
@@ -114,7 +121,7 @@ again:
net.n_net = inet_network(cp);
net.n_addrtype = AF_INET;
q = net.n_aliases = net_aliases;
- if (p != NULL)
+ if (p != NULL)
cp = p;
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {