This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB 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: Why malloc() when target code is executed?


> Date: Mon, 25 Aug 2003 11:25:31 -0700
> From: Kevin Buettner <kevinb@redhat.com>
> 
> 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.

In addition to what Kevin said, if you're truly worried about the
memory leak, you can use a debugger convenience variable -- that way
you have the address and can free it:

    set $hello="Hello\n"
    print printf($hello)
    print free($hello)


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