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 <tom@tromey.com> * python/python.c (python_run_simple_file): Use unique_xmalloc_ptr, gdbpy_ref.
This commit is contained in:
parent
2bd5759dcb
commit
9de10f6d53
2 changed files with 10 additions and 13 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2017-01-10 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* python/python.c (python_run_simple_file): Use
|
||||||
|
unique_xmalloc_ptr, gdbpy_ref.
|
||||||
|
|
||||||
2017-01-10 Tom Tromey <tom@tromey.com>
|
2017-01-10 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* python/py-prettyprint.c (print_stack_unless_memory_error)
|
* python/py-prettyprint.c (print_stack_unless_memory_error)
|
||||||
|
|
|
@ -349,25 +349,17 @@ python_run_simple_file (FILE *file, const char *filename)
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
char *full_path;
|
|
||||||
PyObject *python_file;
|
|
||||||
struct cleanup *cleanup;
|
|
||||||
|
|
||||||
/* Because we have a string for a filename, and are using Python to
|
/* 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. */
|
open the file, we need to expand any tilde in the path first. */
|
||||||
full_path = tilde_expand (filename);
|
gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename));
|
||||||
cleanup = make_cleanup (xfree, full_path);
|
gdbpy_ref python_file (PyFile_FromString (full_path.get (), "r"));
|
||||||
python_file = PyFile_FromString (full_path, "r");
|
if (python_file == NULL)
|
||||||
if (! python_file)
|
|
||||||
{
|
{
|
||||||
do_cleanups (cleanup);
|
|
||||||
gdbpy_print_stack ();
|
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.get ()), filename);
|
||||||
PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
|
|
||||||
do_cleanups (cleanup);
|
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue