summaryrefslogtreecommitdiffstats
path: root/Modules/_threadmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r--Modules/_threadmodule.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index aff755e..aab7ab1 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -27,14 +27,15 @@ typedef struct {
static void
lock_dealloc(lockobject *self)
{
- assert(self->lock_lock);
if (self->in_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
- /* Unlock the lock so it's safe to free it */
- PyThread_acquire_lock(self->lock_lock, 0);
- PyThread_release_lock(self->lock_lock);
-
- PyThread_free_lock(self->lock_lock);
+ if (self->lock_lock != NULL) {
+ /* Unlock the lock so it's safe to free it */
+ PyThread_acquire_lock(self->lock_lock, 0);
+ PyThread_release_lock(self->lock_lock);
+
+ PyThread_free_lock(self->lock_lock);
+ }
PyObject_Del(self);
}
@@ -432,9 +433,9 @@ newlockobject(void)
self->lock_lock = PyThread_allocate_lock();
self->in_weakreflist = NULL;
if (self->lock_lock == NULL) {
- PyObject_Del(self);
- self = NULL;
+ Py_DECREF(self);
PyErr_SetString(ThreadError, "can't allocate lock");
+ return NULL;
}
return self;
}