From 4b8cb9dd9e1fa8dc471f640c592312a751e67eed Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 12 May 2021 13:50:05 -0400 Subject: gdb: make gdbpy_parse_command_name return a unique_xmalloc_ptr This avoids some manual memory management. cmdpy_init correctly transfers ownership of the name to the cmd_list_element, as it sets the name_allocated flag. However, cmdpy_init (and add_setshow_generic) doesn't, it looks like the name is just leaked. This is a bit tricky, because it actually creates two commands (one set and one show), it would take a bit of refactoring of the command code to give each their own allocated copy. For now, just keep doing what the current code does but in a more explicit fashion, with an explicit release. gdb/ChangeLog: * python/python-internal.h (gdbpy_parse_command_name): Return gdb::unique_xmalloc_ptr. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Adjust. * python/py-param.c (parmpy_init): Adjust. (add_setshow_generic): Take gdb::unique_xmalloc_ptr, release it when done. Change-Id: Iae5bc21fe2b22f12d5f954057b0aca7ca4cd3f0d --- gdb/python/python-internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gdb/python/python-internal.h') diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 56702ca..690d2fb 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -439,9 +439,9 @@ PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args); PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args); PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args); PyObject *gdbpy_parameter_value (enum var_types type, void *var); -char *gdbpy_parse_command_name (const char *name, - struct cmd_list_element ***base_list, - struct cmd_list_element **start_list); +gdb::unique_xmalloc_ptr gdbpy_parse_command_name + (const char *name, struct cmd_list_element ***base_list, + struct cmd_list_element **start_list); PyObject *gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *kw); -- cgit v1.1