public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "michael dot kerrisk at gmx dot net" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug manual/1997] opern_memstream() buffer should be freed
Date: Tue, 13 Dec 2005 09:05:00 -0000	[thread overview]
Message-ID: <20051213090540.20073.qmail@sourceware.org> (raw)
In-Reply-To: <20051208155151.1997.michael.kerrisk@gmx.net>


------- Additional Comments From michael dot kerrisk at gmx dot net  2005-12-13 09:05 -------
Subject: Re:  opern_memstream() buffer should be freed

> Von: "decimal at us dot ibm dot com" <sourceware-bugzilla@sourceware.org>

> I took a look in the linux man pages and in the glibc manual and I found
> that while the man page for strdup(3) does say
> 
>   The  strdup()  function  returns  a  pointer to a new string which is a
>   duplicate of the string s.  Memory for the new string is obtained with
>   malloc(3), and can be freed with free(3).
> 
> the glibc manual info entry for strdup() says
> 
> This function copies the null-terminated string s into a newly allocated
> string.
> The string is allocated using malloc; see Unconstrained Allocation. If
> malloc
> cannot allocate space for the new string, strdup returns a null pointer.
> Otherwise it returns a pointer to the new string.
> 
> The section on Unconstrained Allocation includes a section "Freeing after
> Malloc" which discusses free().
> 
> The current section in the glibc manual on open_memstream() says
> 
> This function opens a stream for writing to a buffer. The buffer is
> allocated
> dynamically (as with malloc; see Unconstrained Allocation) and grown as
> necessary.
> 
> So is it really necessary to explicitly mention free() next to every
> function
> which uses malloc()? I'm asking to see if anyone else has a strong
> opinion.

Being the Linux manual page maintainer (but I didn't write that 
strdup(2)) text, I'm inclined to the view that it is useful
to mention free() when describing these interfaces. It is just 
too easy to create memory leaks in C: giving people more direct 
hints (instead of suggesting a hyperlink in the doc, in which it
only becomes clear that free() is needed after quite a bit of 
reading) alerts people to the issue.  

There is a second reason for doing this in the case of 
open_memstream(): the interface is non-standard.  I can determine
from any number of places (my own knowledge, the SUSv3 spec, 
manual pages on various systems) that glibc's strdup() must be 
followed with a free().  However, those sources of information
are not available for open_memstream().

I realise there are differences on documentation philosophy for 
"info" and the manual pages, but I do think an explicit mention of 
free() could be valuable here (and perhaps in a few other places).

Cheers,

Michael



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=1997

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


  parent reply	other threads:[~2005-12-13  9:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-08 15:51 [Bug manual/1997] New: " michael dot kerrisk at gmx dot net
2005-12-12 19:52 ` [Bug manual/1997] " decimal at us dot ibm dot com
2005-12-13  9:05 ` michael dot kerrisk at gmx dot net [this message]
2005-12-13 19:29 ` decimal at us dot ibm dot com
2005-12-13 22:07 ` decimal at us dot ibm dot com
2005-12-13 22:40 ` michael dot kerrisk at gmx dot net
2005-12-13 22:47 ` decimal at us dot ibm dot com
2005-12-14 21:30 ` decimal at us dot ibm dot com
2005-12-14 21:31 ` [Bug manual/1997] open_memstream() " decimal at us dot ibm dot com
2005-12-15 22:30 ` cvs-commit at gcc dot gnu dot org
2006-11-13  5:15 ` jessw at netwood dot net

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051213090540.20073.qmail@sourceware.org \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).