From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26014 invoked by alias); 3 Sep 2003 22:03:36 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 26007 invoked from network); 3 Sep 2003 22:03:35 -0000 Received: from unknown (HELO mail-in-02.arcor-online.net) (151.189.21.42) by sources.redhat.com with SMTP; 3 Sep 2003 22:03:35 -0000 Received: from osc-es.de (dialin-145-254-155-110.arcor-ip.net [145.254.155.110]) by mail-in-02.arcor-online.net (Postfix) with ESMTP id BCF839D08B; Thu, 4 Sep 2003 00:04:54 +0200 (CEST) Message-ID: <3F566526.4000604@osc-es.de> Date: Wed, 03 Sep 2003 22:03:00 -0000 From: Juergen Bohn 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: Ronald Landheer-Cieslak , cygwin@cygwin.com, "Bill C. Riemers" Subject: Re: malloc segfaults References: <3F549C88.9040103@osc-es.de> <20030903094303.GB19365@linux_rln.harvest> In-Reply-To: <20030903094303.GB19365@linux_rln.harvest> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2003-09/txt/msg00243.txt.bz2 Thanks for the hints. gdb and strace show the buggy behavior on my machine. Starting program: /cygdrive/e/verify/malloc/malltest.exe Program received signal SIGSEGV, Segmentation fault. 0x61042e26 in strdup () from /usr/bin/cygwin1.dll (gdb) bt #0 0x61042e26 in strdup () from /usr/bin/cygwin1.dll #1 0x6104326b in mmap64 () from /usr/bin/cygwin1.dll #2 0x61043849 in mmap () from /usr/bin/cygwin1.dll #3 0x610401bc in mktime () from /usr/bin/cygwin1.dll #4 0x61040413 in mktime () from /usr/bin/cygwin1.dll #5 0x610413e6 in malloc () from /usr/bin/cygwin1.dll #6 0x004010e7 in main (argc=1, argv=0xa042630) at malltest.c:10 and 448 1192931 [main] malltest 1472 mmap64: 630000 = mmap() succeeded 249 1193180 [main] malltest 1472 mmap64: addr 0, len 1048576, prot 3, flags 22, fd -1, off 0 202 1193382 [main] malltest 1472 handle_exceptions: In cygwin_except_handler exc 0xC0000005 at 0x61042E26 sp 0x22FCB4 123 1193505 [main] malltest 1472 handle_exceptions: In cygwin_except_handler sig = 11 at 0x61042E26 118 1193623 [main] malltest 1472 handle_exceptions: In cygwin_except_handler calling 0x0 1193743 [main] malltest 1472 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION 120 1193743 [main] malltest 1472 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION The wrapper from Bill Riemer's reply works, at least when I wrap my own malloc() calls. More tips are still appreciated. Best regards, Juergen Ronald Landheer-Cieslak wrote: > Your code may have an unexpected side-effect: printf allocates memory as well. > Try using this: > > #include > > int main(void) > { > void * x; > > x = malloc(1000000); > while (x != NULL) > { > x = malloc(1000000); > if (x == NULL) > write(2, "malloc returned NULL\n", 21); > } > > return(0); > } > > I've tested it under gdb and with strace, both say "malloc returned NULL". OTOH, > when simply run from the command-line, I do get a segmentation fault. > > HTH > > rlc > > On Tue, Sep 02, 2003 at 03:35:04PM +0200, Juergen Bohn wrote: > >>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/