* [patch] getline.3: Emphasize that user code should free the allocated buffer even if getline() failed.
@ 2014-04-02 8:30 Alexey Samsonov
[not found] ` <CAGSYnCNRKxShgzR=WCLOd4BB_4CqEScNsmk-81eytih84cx9gA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Samsonov @ 2014-04-02 8:30 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
>From 4a09a0da31e9b98167e974e05f13f57b53dd41c3 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <samsonov-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Date: Wed, 2 Apr 2014 12:26:44 +0400
Subject: [PATCH] getline.3: Emphasize that user code should free the allocated
buffer even if getline() failed.
---
man3/getline.3 | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/man3/getline.3 b/man3/getline.3
index 806e455..9f403a0 100644
--- a/man3/getline.3
+++ b/man3/getline.3
@@ -69,8 +69,11 @@ is set to NULL and
.I *n
is set 0 before the call, then
.BR getline ()
-will allocate a buffer for storing the line,
-which should be freed by the user program.
+will allocate a buffer for storing the line.
+This buffer should be freed by the user program
+even if
+.BR getline ()
+failed.
Alternatively, before calling
.BR getline (),
--
1.9.1.423.g4596e3a
Relevant discussion in glibc bugzilla:
https://sourceware.org/bugzilla/show_bug.cgi?id=5666
test program:
$ cat tmp/getline/a.cc
#include <stdio.h>
int main() {
for (int x = 0; x < 2; x++) {
char *lineptr = 0;
size_t size = 0;
int res = getline(&lineptr, &size, stdin);
printf("%d\n%p\n", res, lineptr);
}
return 0;
}
$ gcc tmp/getline/a.cc && echo -n "xxx" > tmp/getline/input && ./a.out
< tmp/getline/input
3
0x11ae010
-1
0x11ae090
--
Alexey Samsonov, MSK
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] getline.3: Emphasiqze that user code should free the allocated buffer even if getline() failed.
[not found] ` <CAGSYnCNRKxShgzR=WCLOd4BB_4CqEScNsmk-81eytih84cx9gA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-04-02 10:10 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2014-04-02 10:10 UTC (permalink / raw)
To: Alexey Samsonov
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
linux-man-u79uwXL29TY76Z2rM5mHXA
Hi Alexey,
Good patch, good explanation. Applied.
Thanks!
Cheers,
Michael
On 04/02/2014 10:30 AM, Alexey Samsonov wrote:
>>From 4a09a0da31e9b98167e974e05f13f57b53dd41c3 Mon Sep 17 00:00:00 2001
> From: Alexey Samsonov <samsonov-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> Date: Wed, 2 Apr 2014 12:26:44 +0400
> Subject: [PATCH] getline.3: Emphasize that user code should free the allocated
> buffer even if getline() failed.
>
> ---
> man3/getline.3 | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/man3/getline.3 b/man3/getline.3
> index 806e455..9f403a0 100644
> --- a/man3/getline.3
> +++ b/man3/getline.3
> @@ -69,8 +69,11 @@ is set to NULL and
> .I *n
> is set 0 before the call, then
> .BR getline ()
> -will allocate a buffer for storing the line,
> -which should be freed by the user program.
> +will allocate a buffer for storing the line.
> +This buffer should be freed by the user program
> +even if
> +.BR getline ()
> +failed.
>
> Alternatively, before calling
> .BR getline (),
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-02 10:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-02 8:30 [patch] getline.3: Emphasize that user code should free the allocated buffer even if getline() failed Alexey Samsonov
[not found] ` <CAGSYnCNRKxShgzR=WCLOd4BB_4CqEScNsmk-81eytih84cx9gA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-02 10:10 ` [patch] getline.3: Emphasiqze " Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).