summaryrefslogtreecommitdiff
path: root/libc/misc/mntent
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/misc/mntent
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/misc/mntent')
-rw-r--r--libc/misc/mntent/mntent.c11
1 files changed, 9 insertions, 2 deletions
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);
}