Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
To: cygwin@cygwin.com
From: Andrew Schulman <andrex@alumni.utexas.net>
Subject:  Re: autossh crash with 20050314 and earlier cygwin1.dll [autossh maintainer please note]
Date:  Wed, 16 Mar 2005 12:43:42 -0500
Lines: 34
Message-ID:  <MPG.1ca23a5849180d8a9896d4@localhost>
References:  <20050316162949.GA14571@trixie.casa.cgf.cx>
Mime-Version:  1.0
Content-Type:  text/plain; charset="iso-8859-1"
Content-Transfer-Encoding:  7bit
X-Complaints-To: usenet@sea.gmane.org
X-Gmane-NNTP-Posting-Host: pcp04399769pcs.nrockv01.md.comcast.net
User-Agent: MicroPlanet-Gravity/2.70.2067
X-Archive: encrypt
X-Gmane-MailScanner: Found to be clean
X-Gmane-MailScanner: Found to be clean
X-Gmane-MailScanner-SpamScore: s
X-MailScanner-From: goc-cygwin@m.gmane.org
X-MailScanner-To: cygwin@cygwin.com
X-IsSubscribed: yes

> The problem is that autossh is freeing the return value of
> gethostbyname().  I can't find any reference which says that is a
> acceptable thing to do.  It certainly screws up cygwin, and I can't
> think of any way to avoid having it screw up cygwin.  Maybe it won't
> screw up other systems since they may not malloc the return value of
> gethostbyname.  I dunno.

OK. (hangs head) I have to take the blame for this, because as it 
happens I contributed that bit of code.  Forgive my simplicity on this 
point, but it seemed like good memory heigene-- free up the memory that 
gethostbyname() allocated, once I was done with it.  Looking back now at 
the man page for gethostbyname() (in Linux, there's no Cygwin man page 
AFAIK), it seems unclear on this point:  the NOTES section says "The 
functions gethostbyname() and gethostbyaddr() *may* return pointers to 
static data, which may be overwritten by later calls." (emphasis added)

This may have been a dumb mistake, or not.  Obviously if the memory is 
static, I shouldn't free() it, but the docs are unclear about whether it 
is or not.  Should I infer that I should not free() memory allocated by 
a function that I call unless the man page specifically says to?  Or 
just that it's best not to free() it if it might be static?  This seems 
like a complicated issue and any pointers for this journeyman network 
programmer would be welcome.  Probably OT for this list, though.

> I haven't run an exhaustive test, but the patch below seems to fix this
> problem.

Confirmed, it fixes my crash here with cygwin1.dll snapshot of 2005-Mar-
11.
 
> Could the autossh maintainer look into getting this applied upstream?

Done.  I'll release a new version shortly.
Andrew.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

