This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc segfaults

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;
        if(reserved != NULL)
        reserved = malloc(t+reserved_size);
        unsigned int w=(unsigned int)reserved;
        if(!(0xff800000&(unsigned int)reserved))
        else if(reserved != NULL)
        return retval;

However, none are really satifactory.


----- Original Message ----- 
From: "Juergen Bohn" <>
To: <>
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,
> 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
> does not work to get the number of available pages (_SC_AVPHYS_PAGES, I
> 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:
> Problem reports:
> Documentation:
> FAQ:         

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]