diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-30 22:10:41 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-03 07:59:07 -0600 |
commit | 7f968c899f21643322dcfaf807ec7d7bee7c9974 (patch) | |
tree | cc45bbdc0afdeb352f530fd22795c9a36774d8e0 /gdb/python/py-varobj.c | |
parent | 3c9ebddd93ffb8b44b8cc69f3be9db08c861368e (diff) | |
download | gdb-7f968c899f21643322dcfaf807ec7d7bee7c9974.zip gdb-7f968c899f21643322dcfaf807ec7d7bee7c9974.tar.gz gdb-7f968c899f21643322dcfaf807ec7d7bee7c9974.tar.bz2 |
Avoid some manual memory management in Python
This changes a few places in the Python code to avoid manual memory
management, in favor of letting std::string do the work.
ChangeLog
2017-08-03 Tom Tromey <tom@tromey.com>
* python/python.c (compute_python_string): Return std::string.
(gdbpy_eval_from_control_command): Update.
(do_start_initialization): Use std::string.
* python/py-varobj.c (py_varobj_iter_next): Use string_printf, not
xstrprintf.
* python/py-breakpoint.c (local_setattro): Use string_printf, not
xstrprintf.
Diffstat (limited to 'gdb/python/py-varobj.c')
-rw-r--r-- | gdb/python/py-varobj.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/gdb/python/py-varobj.c b/gdb/python/py-varobj.c index e858556..5f6ab64 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -71,7 +71,6 @@ py_varobj_iter_next (struct varobj_iter *self) if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error)) { PyObject *type, *value, *trace; - char *name_str; PyErr_Fetch (&type, &value, &trace); gdb::unique_xmalloc_ptr<char> @@ -85,10 +84,10 @@ py_varobj_iter_next (struct varobj_iter *self) return NULL; } - name_str = xstrprintf ("<error at %d>", - self->next_raw_index++); - item.reset (Py_BuildValue ("(ss)", name_str, value_str.get ())); - xfree (name_str); + std::string name_str = string_printf ("<error at %d>", + self->next_raw_index++); + item.reset (Py_BuildValue ("(ss)", name_str.c_str (), + value_str.get ())); if (item == NULL) { gdbpy_print_stack (); |