Index: gobject/pygsource.c
===================================================================
--- gobject/pygsource.c	(revision 736)
+++ gobject/pygsource.c	(working copy)
@@ -102,6 +102,9 @@
     }
 
     id = g_source_attach(self->source, context);
+
+    g_source_unref(self->source);
+
     return PyInt_FromLong(id);
 }
 
@@ -110,12 +113,8 @@
 {
     CHECK_DESTROYED(self, NULL);
 
-    if (self->python_source && self->source->context) {
-	PyGRealSource *pysource = (PyGRealSource *)self->source;
-	Py_DECREF(pysource->obj);
-    }
-
     g_source_destroy(self->source);
+
     self->source = NULL;
 
     Py_INCREF(Py_None);
@@ -348,44 +347,22 @@
     return source_repr(self, NULL);
 }
 
-static int
-pyg_source_traverse(PyGSource *self, visitproc visit, void *arg)
+static void
+pyg_source_dealloc(PyGSource *self)
 {
-    int ret = 0;
-
-    if (self->inst_dict) ret = visit(self->inst_dict, arg);
-    if (ret != 0) return ret;
-
-    return 0;
-}
-
-static int
-pyg_source_clear(PyGSource *self)
-{
-    PyObject *tmp;
-
-    tmp = self->inst_dict;
-    self->inst_dict = NULL;
-    Py_XDECREF(tmp);
-
     if (self->source) {
-	g_source_unref(self->source);
+    Py_INCREF(self);
+	GSource* source = self->source;
 	self->source = NULL;
+	g_source_unref(source);
     }
 
-    return 0;
-}
+    if (self->weakreflist)
+        PyObject_ClearWeakRefs((PyObject *)self);
 
-static void
-pyg_source_dealloc(PyGSource *self)
-{
-    PyObject_ClearWeakRefs((PyObject *)self);
+    Py_XDECREF(self->inst_dict);
 
-    PyObject_GC_UnTrack((PyObject *)self);
-
-    pyg_source_clear(self);
-
-    PyObject_GC_Del(self);
+    self->ob_type->tp_free(self);
 }
 
 static gboolean
@@ -504,21 +481,23 @@
 pyg_source_finalize(GSource *source)
 {
     PyGRealSource *pysource = (PyGRealSource *)source;
+    PyGSource* self = pysource->obj;
     PyObject *func, *t;
     PyGILState_STATE state;
 
     state = pyg_gil_state_ensure();
 
-    func = PyObject_GetAttrString(pysource->obj, "finalize");
-    if (func) {
-	t = PyObject_CallObject(func, NULL);
-	Py_DECREF(func);
+	t = PyObject_CallMethod(pysource->obj, "finalize", NULL);
 
 	if (t == NULL) {
 	    PyErr_Print();
 	} else {
 	    Py_DECREF(t);
 	}
+
+    if (self->source) {
+	self->source = NULL;
+	Py_DECREF(pysource->obj);
     }
 
     pyg_gil_state_release(state);
@@ -550,12 +529,6 @@
     return 0;
 }
 
-static void
-pyg_source_free(PyObject *op)
-{
-    PyObject_GC_Del(op);
-}
-
 PyTypeObject PyGSource_Type = {
     PyObject_HEAD_INIT(NULL)
     0,					/* ob_size */
@@ -577,11 +550,10 @@
     (getattrofunc)0,			/* tp_getattro */
     (setattrofunc)0,			/* tp_setattro */
     0,					/* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
-      Py_TPFLAGS_HAVE_GC,		/* tp_flags */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
     NULL,				/* tp_doc */
-    (traverseproc)pyg_source_traverse,	/* tp_traverse */
-    (inquiry)pyg_source_clear,		/* tp_clear */
+    (traverseproc)0,	/* tp_traverse */
+    (inquiry)0,		/* tp_clear */
     (richcmpfunc)0,			/* tp_richcompare */
     offsetof(PyGSource, weakreflist),	/* tp_weaklistoffset */
     (getiterfunc)0,			/* tp_iter */
@@ -597,7 +569,7 @@
     (initproc)pyg_source_init,		/* tp_init */
     (allocfunc)0,			/* tp_alloc */
     (newfunc)0,				/* tp_new */
-    (freefunc)pyg_source_free,		/* tp_free */
+    (freefunc)0,		/* tp_free */
     (inquiry)0,				/* tp_is_gc */
     (PyObject *)0,			/* tp_bases */
 };
@@ -653,8 +625,7 @@
     (getattrofunc)0,			/* tp_getattro */
     (setattrofunc)0,			/* tp_setattro */
     0,					/* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
-      Py_TPFLAGS_HAVE_GC,		/* tp_flags */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
     NULL,				/* tp_doc */
     (traverseproc)0,			/* tp_traverse */
     (inquiry)0,				/* tp_clear */
@@ -730,8 +701,7 @@
     (getattrofunc)0,			/* tp_getattro */
     (setattrofunc)0,			/* tp_setattro */
     0,					/* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
-      Py_TPFLAGS_HAVE_GC,		/* tp_flags */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
     NULL,				/* tp_doc */
     (traverseproc)0,			/* tp_traverse */
     (inquiry)0,				/* tp_clear */
