LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Randy Dunlap <randy.dunlap@oracle.com>
To: "Ahmed S. Darwish" <darwish.07@gmail.com>
Cc: Rob Landley <rob@landley.net>,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	rdunlap@xenotime.net
Subject: Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
Date: Tue, 09 Oct 2007 10:24:03 -0700
Message-ID: <470BB933.8010402@oracle.com> (raw)
In-Reply-To: <20071009171949.GA11579@Ahmed>

Ahmed S. Darwish wrote:
> On Tue, Oct 09, 2007 at 08:55:00AM -0700, Randy Dunlap wrote:
>> On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:
>>
>>> Hi Rob,
>>>
>>> On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
>>> [...]
>>>>  	FILE * infile;
>>>> +
>>>> +	srctree = getenv("SRCTREE");
>>>> +	if (!srctree) srctree = getcwd(NULL,0);
>>>>  	if (argc != 3) {
>>>>  		usage();
>>>>  		exit(1);
>>> $ man getcwd
>>>
>>>  char *getcwd(char *buf, size_t size);
>>>       
>>>  As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
>>>  allocates the buffer dynamically using malloc() if buf is NULL on call.
>>>
>>> Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?
>> What is there to free() at that point?  If getenv() fails (i.e.,
>> the env. variable is not found), it returns NULL.
>> or do I need another cup of coffee?
>>
> 
> I meant if getenv() failed, "srctree = getcwd(NULL, 0)" will let 
> "srctree" point to a _ malloc()ed _ buffer representing PWD. 
> As said in the manpage, this buffer needs to be free()ed after usage.
> Right or I'm the one who needs that cup of coffee :) ?

so it needs to be freed at program termination, is that what you are
saying?  That will happen automatically (along with any open files being
closed, etc.).

-- 
~Randy

  reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-09  6:25 Rob Landley
2007-10-09 13:03 ` Ahmed S. Darwish
2007-10-09 15:55   ` Randy Dunlap
2007-10-09 17:19     ` Ahmed S. Darwish
2007-10-09 17:24       ` Randy Dunlap [this message]
2007-10-09 17:51         ` Ahmed S. Darwish
2007-10-09 22:19   ` Rob Landley
2007-10-09 15:56 ` Randy Dunlap
2007-10-18 11:53 ` Sam Ravnborg

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=470BB933.8010402@oracle.com \
    --to=randy.dunlap@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=darwish.07@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    --cc=rob@landley.net \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lkml.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lkml.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lkml.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lkml.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lkml.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lkml.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lkml.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lkml.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lkml.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lkml.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lkml.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lkml.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git