From e32376aaed01ed44981386e348ac35b58da23495 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 18 Mar 2004 11:12:34 +0000 Subject: 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? --- libc/misc/mntent/mntent.c | 11 +++++++++-- libc/misc/ttyent/getttyent.c | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c index 93d591812..d98a6870f 100644 --- a/libc/misc/mntent/mntent.c +++ b/libc/misc/mntent/mntent.c @@ -65,10 +65,17 @@ struct mntent *getmntent_r (FILE *filep, struct mntent *getmntent(FILE * filep) { struct mntent *tmp; - static char buff[BUFSIZ]; + static char *buff = NULL; static struct mntent mnt; LOCK; - tmp = getmntent_r(filep, &mnt, buff, sizeof buff); + + if (!buff) { + buff = malloc(BUFSIZ); + if (!buff) + abort(); + } + + tmp = getmntent_r(filep, &mnt, buff, BUFSIZ); UNLOCK; return(tmp); } diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c index 18b9109af..0b2c9a3cc 100644 --- a/libc/misc/ttyent/getttyent.c +++ b/libc/misc/ttyent/getttyent.c @@ -99,11 +99,19 @@ struct ttyent * getttyent(void) { register int c; register char *p; - static char line[BUFSIZ]; + static char *line = NULL; if (!tf && !setttyent()) return (NULL); + + if (!line) { + line = malloc(BUFSIZ); + if (!line) + abort(); + } + flockfile (tf); + for (;;) { if (!fgets_unlocked(p = line, sizeof(line), tf)) { funlockfile (tf); -- cgit v1.2.3