This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Freeing memory allocated in the inferior
- From: Matthew Malcomson <hardenedapple at gmail dot com>
- To: gdb at sourceware dot org
- Date: Mon, 20 Feb 2017 10:11:56 +0000
- Subject: Freeing memory allocated in the inferior
- Authentication-results: sourceware.org; auth=none
Hello,
I've just been reading the code, and was hoping someone could help me
understand something.
It seems that memory allocated in the inferior (with
`value_allocate_space_in_inferior()` is never freed, even when the gdb
process exits/detaches.
Is this true (i.e. have I missed something)?
I found an old comment on an old bug that implies this is correct
https://sourceware.org/bugzilla/show_bug.cgi?id=16236#c1, and the
pointer appears to remain valid in the inferior over a lot of allocation
after detaching, but neither of those are particularly conclusive.
If so, why is this?
I can see it would be difficult to know when to free them during
execution, because the user may simply remember the pointer address the
variable is stored and attempt to use it, but what about storing the
allocations on a data structure somewhere, and freeing them when gdb is
closing/detaching?
I doubt many users are remembering pointer addresses after having
detached and attached again to a process, but I guess there could be an
extra `set` parameter introduced if this were the case.