diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-08-20 18:17:36 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-08-20 18:17:36 +0000 |
commit | 563c34e23306f58a95951a2e5587d3ec14a7fe4b (patch) | |
tree | e8d4ffa8ee2bb3cdcb3de53f47ee20913ad0ab44 /lib/libc | |
parent | 0ac2182c1049d52b35fc679fa3fd6ad0c63f0f7b (diff) |
Don't need to check lbuf != NULL when free()ing it. In addition,
since the EOF w/o EOL can only happen for the last line, move the
free() outside the loop so we only do it once. OK otto@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/fgetln.3 | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/libc/stdio/fgetln.3 b/lib/libc/stdio/fgetln.3 index 18e2d038168..78a96dc6ed4 100644 --- a/lib/libc/stdio/fgetln.3 +++ b/lib/libc/stdio/fgetln.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fgetln.3,v 1.10 2003/06/02 20:18:37 millert Exp $ +.\" $OpenBSD: fgetln.3,v 1.11 2004/08/20 18:17:35 millert Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -133,6 +133,7 @@ temporary buffer: if (buf[len - 1] == '\en') buf[len - 1] = '\e0'; else { + /* EOF without EOL, copy and add the NUL */ if ((lbuf = (char *)malloc(len + 1)) == NULL) err(1, NULL); memcpy(lbuf, buf, len); @@ -140,10 +141,6 @@ temporary buffer: buf = lbuf; } printf("%s\en", buf); - - if (lbuf != NULL) { - free(lbuf); - lbuf = NULL; - } } + free(lbuf); .Ed |