From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14620 invoked by alias); 4 Jul 2012 13:48:41 -0000 Received: (qmail 14503 invoked by uid 22791); 4 Jul 2012 13:48:40 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,MAY_BE_FORGED,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from bureau85.ns.utoronto.ca (HELO bureau85.ns.utoronto.ca) (128.100.132.185) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 04 Jul 2012 13:48:25 +0000 Received: from [192.168.0.100] (184-175-12-167.dsl.teksavvy.com [184.175.12.167] (may be forged)) (authenticated bits=0) by bureau85.ns.utoronto.ca (8.13.8/8.13.8) with ESMTP id q64DmLXl021236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 4 Jul 2012 09:48:23 -0400 Message-ID: <4FF449A6.5060102@cs.utoronto.ca> Date: Wed, 04 Jul 2012 13:48:00 -0000 From: Ryan Johnson User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Re: Differences between C++ 'new' operator and 'malloc()' (NOT a C/C++ question) References: <8ef10a0d4a6912c0aa23bc33eebbe95d.squirrel@zeusw.org> In-Reply-To: <8ef10a0d4a6912c0aa23bc33eebbe95d.squirrel@zeusw.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2012-07/txt/msg00045.txt.bz2 On 04/07/2012 5:45 AM, Claude SIMON wrote: > When I compile the component with Visual C++, it works. When I compile the > component with g++... it crashes. > > With 'gdb', I found that the problem happens when calling the 'malloc' > function (as soon as the function is called, NOT when the returned > allocated memory is used). When I replace the 'malloc' by a the C++ 'new' > operator, the component compiled with Cygwin g++ doesn't crash anymore. > I thought that the C++ 'new' operator calls the 'malloc' function, but > this seems not to be the case. As I want to use 'malloc'-like functions > rather than the C++ 'new' operator, I wonder which functions are used in > the C++ 'new' operator to allocate memory (and naturally which functions > are used in the C++ 'delete' operator to free the memory). Operator new() and malloc() are explicitly *not* interchangeable (for many reasons, not least of which that the Standard says so). If you were to free new'ed memory, or delete malloc'ed memory, the resulting heap corruption could easily manifest as a crash the next time you tried to allocate something... or it might just silently clobber data and lead to "spooky action at a distance." Ryan -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple