From: Tom Tromey Date: Sat, 12 Nov 2016 19:08:17 +0000 (-0700) Subject: Change python_run_simple_file to use gdbpy_ref X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9de10f6d53dffbec12cec9843662d5764526983d;p=binutils-gdb.git Change python_run_simple_file to use gdbpy_ref This changes python_run_simple_file to use gdbpy_ref and unique_xmalloc_ptr. Thi fixes a latent bug in this function, where the error path previously ran the cleanups and then referred to one of the objects just freed. 2017-01-10 Tom Tromey * python/python.c (python_run_simple_file): Use unique_xmalloc_ptr, gdbpy_ref. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 870b300eebd..7f57d7f2786 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-01-10 Tom Tromey + + * python/python.c (python_run_simple_file): Use + unique_xmalloc_ptr, gdbpy_ref. + 2017-01-10 Tom Tromey * python/py-prettyprint.c (print_stack_unless_memory_error) diff --git a/gdb/python/python.c b/gdb/python/python.c index 9b5efa1c3c3..768d0a8d2ef 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -349,25 +349,17 @@ python_run_simple_file (FILE *file, const char *filename) #else /* _WIN32 */ - char *full_path; - PyObject *python_file; - struct cleanup *cleanup; - /* Because we have a string for a filename, and are using Python to open the file, we need to expand any tilde in the path first. */ - full_path = tilde_expand (filename); - cleanup = make_cleanup (xfree, full_path); - python_file = PyFile_FromString (full_path, "r"); - if (! python_file) + gdb::unique_xmalloc_ptr full_path (tilde_expand (filename)); + gdbpy_ref python_file (PyFile_FromString (full_path.get (), "r")); + if (python_file == NULL) { - do_cleanups (cleanup); gdbpy_print_stack (); - error (_("Error while opening file: %s"), full_path); + error (_("Error while opening file: %s"), full_path.get ()); } - make_cleanup_py_decref (python_file); - PyRun_SimpleFile (PyFile_AsFile (python_file), filename); - do_cleanups (cleanup); + PyRun_SimpleFile (PyFile_AsFile (python_file.get ()), filename); #endif /* _WIN32 */ }