Fix get_core_register_section leak, introduce thread_section_name
authorPedro Alves <palves@redhat.com>
Thu, 4 May 2017 14:14:37 +0000 (15:14 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 4 May 2017 14:14:37 +0000 (15:14 +0100)
commit3c3ae77e68a9032ef9f174bf6b1cc992b6a4cb35
tree424cbaa533c75fa1df717e6164245fff595efec0
parentf91d48deb29d9e6f4b530f586db0140943ed0d83
Fix get_core_register_section leak, introduce thread_section_name

This plugs a leak introduced in the previous change to
get_core_register_section, which removed an xfree call that is
actually necessary because the 'section_name' local is static.

From [1] it looks like the reason the variable was made static to
begin with, was just "laziness" to avoid having to think about freeing
it on every function return path:

 https://sourceware.org/ml/gdb-patches/2005-03/msg00237.html

The easiest to fix that nowadays is to use a std::string.

I don't see a need to xstrdup the section name in the single-threaded
case though, and also there's more than one place that computes a
multi-threaded section name in the same way.  So put the section name
computation in a wrapper class with state.

gdb/ChangeLog:
2017-05-04  Pedro Alves  <palves@redhat.com>

* corelow.c (thread_section_name): New class.
(get_core_register_section, get_core_siginfo): Use it.
gdb/ChangeLog
gdb/corelow.c