From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24694 invoked by alias); 25 Aug 2003 19:57:21 -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 24639 invoked from network); 25 Aug 2003 19:57:10 -0000 Received: from unknown (HELO mail.inka.de) (193.197.184.2) by sources.redhat.com with SMTP; 25 Aug 2003 19:57:10 -0000 Received: from raven.inka.de (uucp@[127.0.0.1]) by mail.inka.de with uucp (rmailwrap 0.5) id 19rNSf-0003CG-00; Mon, 25 Aug 2003 21:57:09 +0200 Received: from localhost (localhost [127.0.0.1]) by raven.inka.de (Postfix) with ESMTP id 34EDF1B8; Mon, 25 Aug 2003 21:56:36 +0200 (CEST) Received: by raven.inka.de (Postfix, from userid 500) id E0AF61C2; Mon, 25 Aug 2003 21:56:35 +0200 (CEST) Date: Mon, 25 Aug 2003 19:57:00 -0000 From: Josef Wolf To: Kevin Buettner Cc: gdb@sources.redhat.com Subject: Re: Why malloc() when target code is executed? Message-ID: <20030825195635.GA32349@raven.inka.de> References: <20030822204844.GC14466@raven.inka.de> <1030825182531.ZM9704@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1030825182531.ZM9704@localhost.localdomain> User-Agent: Mutt/1.4i X-Virus-Scanned: by AMaViS snapshot-20020531 X-SW-Source: 2003-08/txt/msg00283.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. -- Please visit and sign http://petition-eurolinux.org and http://www.ffii.org -- Josef Wolf -- jw@raven.inka.de --