diff options
| author | Martin Pitt <martinpitt@gnome.org> | 2013-02-28 11:43:47 +0100 |
|---|---|---|
| committer | Martin Pitt <martinpitt@gnome.org> | 2013-02-28 11:43:47 +0100 |
| commit | 105e6738ee249b64904da26ae45dd273ca4eeba8 (patch) | |
| tree | 36ec13eb32fc16ad538931026f6e37e0d2a521d8 /gi/pygi-boxed.c | |
| parent | 64bcca2d39fed1734ad1abbe291406387e901f5c (diff) | |
| download | pygobject-105e6738ee249b64904da26ae45dd273ca4eeba8.tar.gz | |
Fix leak of caller-allocated boxed values
Add a new "allocated_slice" argument to _pygi_boxed_new() which specifies
whether its "boxed" pointer was allocated using a slice (by giving its size) or
malloc (by specifying 0), as _pygi_boxed_new cannot determine that itself any
more.
Use this in _pygi_marshal_to_py_interface_struct() for caller-allocated boxed
values, as _caller_alloc() uses _pygi_boxed_alloc() for those (i. e. slices),
which would otherwise leak.
Thanks to Mike Gorse <mgorse@suse.com> for the original patch!
https://bugzilla.gnome.org/show_bug.cgi?id=691501
Diffstat (limited to 'gi/pygi-boxed.c')
| -rw-r--r-- | gi/pygi-boxed.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c index c15c927a..cac2b0d8 100644 --- a/gi/pygi-boxed.c +++ b/gi/pygi-boxed.c @@ -104,7 +104,7 @@ _boxed_new (PyTypeObject *type, goto out; } - self = (PyGIBoxed *) _pygi_boxed_new (type, boxed, TRUE); + self = (PyGIBoxed *) _pygi_boxed_new (type, boxed, TRUE, size); if (self == NULL) { g_slice_free1 (size, boxed); goto out; @@ -133,7 +133,8 @@ PYGLIB_DEFINE_TYPE("gi.Boxed", PyGIBoxed_Type, PyGIBoxed); PyObject * _pygi_boxed_new (PyTypeObject *type, gpointer boxed, - gboolean free_on_dealloc) + gboolean free_on_dealloc, + gsize allocated_slice) { PyGIBoxed *self; @@ -154,8 +155,13 @@ _pygi_boxed_new (PyTypeObject *type, ( (PyGBoxed *) self)->gtype = pyg_type_from_object ( (PyObject *) type); ( (PyGBoxed *) self)->boxed = boxed; ( (PyGBoxed *) self)->free_on_dealloc = free_on_dealloc; - self->size = 0; - self->slice_allocated = FALSE; + if (allocated_slice > 0) { + self->size = allocated_slice; + self->slice_allocated = TRUE; + } else { + self->size = 0; + self->slice_allocated = FALSE; + } return (PyObject *) self; } |
