delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/03/16/13:12:22

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
From: Andrew Schulman <andrex AT alumni DOT utexas DOT 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 DOT GA14571 AT trixie DOT casa DOT cgf DOT cx>
Mime-Version: 1.0
X-Complaints-To: usenet AT sea DOT gmane DOT 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 AT m DOT gmane DOT org
X-MailScanner-To: cygwin AT cygwin DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019