summaryrefslogtreecommitdiff
path: root/gi/pygi-boxed.c
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu@centricular.com>2018-01-23 14:15:19 +0100
committerMathieu Duponchelle <mathieu@centricular.com>2018-01-23 23:36:41 +0100
commit9d96df1ea3ad533885fbcae4de693a3cd81e765a (patch)
tree41c11a46edd1c2d8025689f076fdef463aec653e /gi/pygi-boxed.c
parentdaefdfa3e4dc97b4ae38250358d722f09764cc9b (diff)
downloadpygobject-9d96df1ea3ad533885fbcae4de693a3cd81e765a.tar.gz
pygi-boxed: make in-place copy safer
Making sure we don't attempt to g_boxed_copy a NULL pointer, as this is explicitly disallowed, and setting slice-allocated to FALSE once g_slice_free has been called.
Diffstat (limited to 'gi/pygi-boxed.c')
-rw-r--r--gi/pygi-boxed.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index fa690bb3..599d6d3e 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -42,6 +42,8 @@ boxed_del (PyGIBoxed *self)
if ( ( (PyGBoxed *) self)->free_on_dealloc && boxed != NULL) {
if (self->slice_allocated) {
g_slice_free1 (self->size, boxed);
+ self->slice_allocated = FALSE;
+ self->size = 0;
} else {
g_type = pyg_type_from_object ( (PyObject *) self);
g_boxed_free (g_type, boxed);
@@ -203,7 +205,11 @@ void
_pygi_boxed_copy_in_place (PyGIBoxed *self)
{
PyGBoxed *pygboxed = (PyGBoxed *)self;
- gpointer copy = g_boxed_copy (pygboxed->gtype, pyg_boxed_get_ptr (self));
+ gpointer ptr = pyg_boxed_get_ptr (self);
+ gpointer copy = NULL;
+
+ if (ptr)
+ copy = g_boxed_copy (pygboxed->gtype, ptr);
boxed_del (self);
pyg_boxed_set_ptr (pygboxed, copy);