delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/09/02/17:09:21

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: <017f01c37193$f4c9c160$c900000a@docbill002>
From: "Bill C. Riemers" <cygwin AT docbill DOT net>
To: "Juergen Bohn" <bohn AT osc-es DOT de>, <cygwin AT cygwin DOT com>
References: <3F549C88 DOT 9040103 AT osc-es DOT de>
Subject: Re: malloc segfaults
Date: Tue, 2 Sep 2003 16:50:40 -0400
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165

Definitely looks like a cygwin1.dll bug to me.  I see consistently the
traceback either terminates in
strdup() called from mmap64(), or mktime() called from strdup().  There are
a number of hacks you
can do to work around the bug.  i..e.:

void *malloc_wrapper(size_t t)
{
        static const size_t reserved_size=32768;
        static void *reserved=NULL;
        void *retval=NULL;
        printf("reserved=%x,%x\n",reserved,t+reserved_size);
        if(reserved != NULL)
        {
                free(reserved);
        }
        reserved = malloc(t+reserved_size);
        unsigned int w=(unsigned int)reserved;
        if(!(0xff800000&(unsigned int)reserved))
        {
                free(reserved);
        }
        else if(reserved != NULL)
        {
                free(reserved);
                retval=malloc(t);
        }
        reserved=malloc(reserved_size);
        return retval;
}

However, none are really satifactory.

                                Bill


----- Original Message ----- 
From: "Juergen Bohn" <bohn AT osc-es DOT de>
To: <cygwin AT cygwin DOT com>
Sent: Tuesday, September 02, 2003 9:35 AM
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/
>



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