[uClibc-cvs] uClibc/libc/misc/mntent mntent.c,1.6,1.7

Erik Andersen andersen at uclibc.org
Thu Mar 18 11:12:36 UTC 2004


Update of /var/cvs/uClibc/libc/misc/mntent
In directory nail:/tmp/cvs-serv7322/libc/misc/mntent

Modified Files:
	mntent.c 
Log Message:
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?


Index: mntent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/misc/mntent/mntent.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/mntent.c	27 Dec 2003 23:30:32 -0000	1.6
+++ b/mntent.c	18 Mar 2004 11:12:33 -0000	1.7
@@ -65,10 +65,17 @@
 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);
 }




More information about the uClibc-cvs mailing list