diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8381b8e842f..9179abf15b7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-04-27 Simon Marchi + + * python/py-inferior.c (inferior_to_inferior_object): Increment reference + count when creating the object. + 2017-04-27 Sangamesh Mallayya Ulrich Weigand diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 3d2cb1ddbeb..f6a24a090f2 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -223,11 +223,14 @@ inferior_to_inferior_object (struct inferior *inferior) inf_obj->threads = NULL; inf_obj->nthreads = 0; + /* PyObject_New initializes the new object with a refcount of 1. This + counts for the reference we are keeping in the inferior data. */ set_inferior_data (inferior, infpy_inf_data_key, inf_obj); } - else - Py_INCREF ((PyObject *)inf_obj); + + /* We are returning a new reference. */ + Py_INCREF ((PyObject *)inf_obj); return (PyObject *) inf_obj; }