From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29038 invoked by alias); 25 Aug 2003 22:08:03 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 29030 invoked from network); 25 Aug 2003 22:08:01 -0000 Received: from unknown (HELO localhost.redhat.com) (207.219.125.105) by sources.redhat.com with SMTP; 25 Aug 2003 22:08:01 -0000 Received: from redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 94D022B7F; Mon, 25 Aug 2003 18:08:03 -0400 (EDT) Message-ID: <3F4A88C3.4030603@redhat.com> Date: Mon, 25 Aug 2003 22:08:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.2) Gecko/20030820 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Josef Wolf Cc: Kevin Buettner , gdb@sources.redhat.com Subject: Re: Why malloc() when target code is executed? References: <20030822204844.GC14466@raven.inka.de> <1030825182531.ZM9704@localhost.localdomain> <20030825195635.GA32349@raven.inka.de> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2003-08/txt/msg00284.txt.bz2 > On Mon, Aug 25, 2003 at 11:25:31AM -0700, Kevin Buettner wrote: > >> On Aug 22, 10:48pm, Josef Wolf wrote: >> > >> > I just noticed that ``print printf("Hello\n")'' call malloc() on the >> > target to allocate the memory for the string. AFAICS, this memory >> > never gets freed. Is there any reason not to allocate this memory >> > on the stack? This would avoid this memory leak. In addition, this >> > would make it possible to use this feature on embedded systems which >> > often have either restricted memory or even dont have malloc() at all. > >> >> For printf(), allocating the string on the stack is (usually) okay. >> This is because printf() doesn't return a pointer to the string nor >> does it write the string pointer to some data structure in the >> inferior process. Functions which did either of these could/would end >> up with a dangling pointer if the string were to be allocated on the >> stack. > > > Ahhh, I see there is good reason for current behavior. Had not thought > about this one. Thanks for clarifying this. The doco should probably mention this. What to file a bug report (or a patch?). Andrew