(re-)fix the regcache leaks when detaching from an executable.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 24 Mar 2019 10:44:00 +0000 (11:44 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 24 Mar 2019 12:56:46 +0000 (13:56 +0100)
commit5783e150b2a9308e23262a5b62f5d51c8c932ece
treecfa98366ac130a422bf33e7c0b9a7e380f21c0e6
parent83bfc77ff537667989bd375b991d379ee4dda350
(re-)fix the regcache leaks when detaching from an executable.

Commit 799efbe8e01ab8292c01f46ac59a6fb2349d4535 was supposed to fix
the below leak.  However, for this fix to work, it is critical to
save the ptid before detach.

This commit (pushed as OBVIOUS, as the change was already reviewed/approved)
saves the ptid before the detach, as in the original reviewed patch
(see https://sourceware.org/ml/gdb-patches/2019-02/msg00263.html).

Re-tested on debian/amd64, natively and under valgrind.

==7426== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,872 of 3,020
==7426==    at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==7426==    by 0x5BD1E1: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330)
==7426==    by 0x5BD39A: get_thread_regcache (regcache.c:366)
==7426==    by 0x5BD39A: get_current_regcache() (regcache.c:372)
==7426==    by 0x4B1EB4: get_current_frame() (frame.c:1588)
...
gdb/target.c