diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | gobject/pygenum.c | 18 | ||||
-rw-r--r-- | gobject/pygflags.c | 20 |
3 files changed, 36 insertions, 12 deletions
@@ -1,3 +1,13 @@ +2006-03-09 Michael Smith <msmith@fluendo.com> + + reviewed by: Johan Dahlin <jdahlin@async.com.br> + + * gobject/pygenum.c: (pyg_enum_new), (pyg_enum_from_gtype), + (pyg_enum_add): + * gobject/pygflags.c: (pyg_flags_new), (pyg_flags_from_gtype), + (pyg_flags_add): + Plug a couple of leaks, fixes #334027. + 2006-01-19 Johan Dahlin <johan@gnome.org> * configure.ac (export_dynamic): diff --git a/gobject/pygenum.c b/gobject/pygenum.c index aa8907e..2c0ee12 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -73,7 +73,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "value", NULL }; long value; - PyObject *pytc, *values, *ret; + PyObject *pytc, *values, *ret, *intvalue; GType gtype; GEnumClass *eclass; @@ -117,7 +117,9 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) g_type_class_unref(eclass); - ret = PyDict_GetItem(values, PyInt_FromLong(value)); + intvalue = PyInt_FromLong(value); + ret = PyDict_GetItem(values, intvalue); + Py_DECREF(intvalue); Py_DECREF(values); if (ret) Py_INCREF(ret); @@ -130,7 +132,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyObject* pyg_enum_from_gtype (GType gtype, int value) { - PyObject *pyclass, *values, *retval; + PyObject *pyclass, *values, *retval, *intvalue; g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL); @@ -143,7 +145,9 @@ pyg_enum_from_gtype (GType gtype, int value) values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict, "__enum_values__"); - retval = PyDict_GetItem(values, PyInt_FromLong(value)); + intvalue = PyInt_FromLong(value); + retval = PyDict_GetItem(values, intvalue); + Py_DECREF(intvalue); if (!retval) { PyErr_Clear(); retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0); @@ -210,13 +214,15 @@ pyg_enum_add (PyObject * module, values = PyDict_New(); for (i = 0; i < eclass->n_values; i++) { - PyObject *item; + PyObject *item, *intval; item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0); ((PyIntObject*)item)->ob_ival = eclass->values[i].value; ((PyGEnum*)item)->gtype = gtype; - PyDict_SetItem(values, PyInt_FromLong(eclass->values[i].value), item); + intval = PyInt_FromLong(eclass->values[i].value); + PyDict_SetItem(values, intval, item); + Py_DECREF(intval); if (module) { PyModule_AddObject(module, diff --git a/gobject/pygflags.c b/gobject/pygflags.c index 562ea02..2fcfa10 100644 --- a/gobject/pygflags.c +++ b/gobject/pygflags.c @@ -105,7 +105,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "value", NULL }; long value; - PyObject *pytc, *values, *ret; + PyObject *pytc, *values, *ret, *pyint; GType gtype; GFlagsClass *eclass; @@ -143,8 +143,11 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) g_type_class_unref(eclass); - ret = PyDict_GetItem(values, PyInt_FromLong(value)); + pyint = PyInt_FromLong(value); + ret = PyDict_GetItem(values, pyint); + Py_DECREF(pyint); Py_DECREF(values); + if (ret) Py_INCREF(ret); else @@ -155,7 +158,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyObject* pyg_flags_from_gtype (GType gtype, int value) { - PyObject *pyclass, *values, *retval; + PyObject *pyclass, *values, *retval, *pyint; g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL); @@ -169,7 +172,10 @@ pyg_flags_from_gtype (GType gtype, int value) values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict, "__flags_values__"); - retval = PyDict_GetItem(values, PyInt_FromLong(value)); + pyint = PyInt_FromLong(value); + retval = PyDict_GetItem(values, pyint); + Py_DECREF(pyint); + if (!retval) { PyErr_Clear(); @@ -234,13 +240,15 @@ pyg_flags_add (PyObject * module, values = PyDict_New(); for (i = 0; i < eclass->n_values; i++) { - PyObject *item; + PyObject *item, *intval; item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0); ((PyIntObject*)item)->ob_ival = eclass->values[i].value; ((PyGFlags*)item)->gtype = gtype; - PyDict_SetItem(values, PyInt_FromLong(eclass->values[i].value), item); + intval = PyInt_FromLong(eclass->values[i].value); + PyDict_SetItem(values, intval, item); + Py_DECREF(intval); if (module) { PyModule_AddObject(module, |