[uClibc-cvs] uClibc/libc/misc/ttyent getttyent.c,1.3,1.4
Erik Andersen
andersen at uclibc.org
Thu Mar 18 11:12:36 UTC 2004
Update of /var/cvs/uClibc/libc/misc/ttyent
In directory nail:/tmp/cvs-serv7322/libc/misc/ttyent
Modified Files:
getttyent.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: getttyent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/misc/ttyent/getttyent.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/getttyent.c 17 Jun 2002 19:02:01 -0000 1.3
+++ b/getttyent.c 18 Mar 2004 11:12:34 -0000 1.4
@@ -99,11 +99,19 @@
{
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);
More information about the uClibc-cvs
mailing list