From b6305346bd372b9dc399b6c1b4f6d98b7b272990 Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 7 Oct 2015 16:53:00 +0000 Subject: [PATCH] Be explicit that the user is responsible for freeing the line buffer and show this in the example. --- lib/libc/stdio/getdelim.3 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/libc/stdio/getdelim.3 b/lib/libc/stdio/getdelim.3 index 743d32704ae..45044f86df6 100644 --- a/lib/libc/stdio/getdelim.3 +++ b/lib/libc/stdio/getdelim.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getdelim.3,v 1.2 2015/09/10 14:00:14 schwarze Exp $ +.\" $OpenBSD: getdelim.3,v 1.3 2015/10/07 16:53:00 millert Exp $ .\" $NetBSD: getdelim.3,v 1.9 2011/04/20 23:37:51 enami Exp $ .\" .\" Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: September 10 2015 $ +.Dd $Mdocdate: October 7 2015 $ .Dt GETDELIM 3 .Os .Sh NAME @@ -71,11 +71,16 @@ it must be possible to .Xr free 3 .Fa *lineptr . .Fn getdelim -ensures that +will +.Xr realloc 3 .Fa *lineptr -is large enough to hold the input, updating +as necessary, updating .Fa *n to reflect the new size. +It is the responsibility of the caller to +.Xr free 3 +.Fa *lineptr +when it is no longer needed. .Pp The .Fn getline @@ -113,6 +118,7 @@ ssize_t linelen; while ((linelen = getline(\*[Am]line, \*[Am]linesize, fp)) != -1) fwrite(line, linelen, 1, stdout); +free(line); if (ferror(fp)) perror("getline"); .Ed -- 2.20.1