delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/09/02/12:40:03

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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
Message-ID: <3F549C88.9040103@osc-es.de>
Date: Tue, 02 Sep 2003 15:35:04 +0200
From: Juergen Bohn <bohn AT osc-es DOT de>
Organization: OSC Embedded Systems
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: malloc segfaults

Tested with cygwin1.dll 1.5.3-1 and 1.3.22-1 on Win2000-SP4, malloc() does 
not (always)
return NULL if there is no more memory available.  Try, for example, simple 
loops like:

   x = malloc(10000);
   for (i=0; x != NULL; i++)
   {
       x = malloc(10000);
       if (x == NULL)    printf("x is NULL\n");
   }

My application terminates with a segmentation violation, but all attempts 
to handle this by signal() or atexit() fail.  Unfortunately, also sysconf() 
does not work to get the number of available pages (_SC_AVPHYS_PAGES, I get 
always the same but wrong value).

While testing, I detected that errno is set to 12 ("Not enough memory") 
after enough iterations through the for-loop above, while variable x still 
is not zero.  But still my application crashes even when I break the loop 
at errno!=0.

Is there any secure way to find out, how much memory is available (or hope 
that the malloc() problems will be solved)?

Many thanks,
Juergen



--
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