mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
python: Safely clear structure members
Using Py_CLEAR() ensures that these structures are observed in a consistent state by any Python code that may run during deconstruction. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
8d6e447340
commit
f573177c35
@ -2134,10 +2134,7 @@ static int py_ldb_search_iterator_reply_destructor(struct py_ldb_search_iterator
|
||||
reply->py_iter = NULL;
|
||||
}
|
||||
|
||||
if (reply->obj != NULL) {
|
||||
Py_DECREF(reply->obj);
|
||||
reply->obj = NULL;
|
||||
}
|
||||
Py_CLEAR(reply->obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2679,9 +2676,9 @@ static PyTypeObject PyLdb = {
|
||||
static void py_ldb_result_dealloc(PyLdbResultObject *self)
|
||||
{
|
||||
talloc_free(self->mem_ctx);
|
||||
Py_DECREF(self->msgs);
|
||||
Py_DECREF(self->referals);
|
||||
Py_DECREF(self->controls);
|
||||
Py_CLEAR(self->msgs);
|
||||
Py_CLEAR(self->referals);
|
||||
Py_CLEAR(self->controls);
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
}
|
||||
|
||||
@ -2775,10 +2772,10 @@ static PyTypeObject PyLdbResult = {
|
||||
|
||||
static void py_ldb_search_iterator_dealloc(PyLdbSearchIteratorObject *self)
|
||||
{
|
||||
Py_XDECREF(self->state.exception);
|
||||
Py_CLEAR(self->state.exception);
|
||||
TALLOC_FREE(self->mem_ctx);
|
||||
ZERO_STRUCT(self->state);
|
||||
Py_DECREF(self->ldb);
|
||||
Py_CLEAR(self->ldb);
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
}
|
||||
|
||||
@ -2885,7 +2882,7 @@ static PyObject *py_ldb_search_iterator_abandon(PyLdbSearchIteratorObject *self,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_XDECREF(self->state.exception);
|
||||
Py_CLEAR(self->state.exception);
|
||||
TALLOC_FREE(self->mem_ctx);
|
||||
ZERO_STRUCT(self->state);
|
||||
Py_RETURN_NONE;
|
||||
@ -4289,7 +4286,7 @@ static int py_module_del_transaction(struct ldb_module *mod)
|
||||
|
||||
static int py_module_destructor(struct ldb_module *mod)
|
||||
{
|
||||
Py_DECREF((PyObject *)mod->private_data);
|
||||
Py_CLEAR(mod->private_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
|
||||
|
||||
static void tdb_iter_dealloc(PyTdbIteratorObject *self)
|
||||
{
|
||||
Py_DECREF(self->iteratee);
|
||||
Py_CLEAR(self->iteratee);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ static void py_tevent_timer_dealloc(TeventTimer_Object *self)
|
||||
if (self->timer) {
|
||||
talloc_free(self->timer);
|
||||
}
|
||||
Py_DECREF(self->callback);
|
||||
Py_CLEAR(self->callback);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ struct TeventTimer_Object_ref {
|
||||
static int TeventTimer_Object_ref_destructor(struct TeventTimer_Object_ref *ref)
|
||||
{
|
||||
ref->obj->timer = NULL;
|
||||
Py_DECREF(ref->obj);
|
||||
Py_CLEAR(ref->obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1668,10 +1668,7 @@ struct py_cli_notify_state {
|
||||
static void py_cli_notify_state_dealloc(struct py_cli_notify_state *self)
|
||||
{
|
||||
TALLOC_FREE(self->req);
|
||||
if (self->py_cli_state != NULL) {
|
||||
Py_DECREF(self->py_cli_state);
|
||||
self->py_cli_state = NULL;
|
||||
}
|
||||
Py_CLEAR(self->py_cli_state);
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
}
|
||||
|
||||
@ -1823,8 +1820,7 @@ static PyObject *py_cli_notify_get_changes(struct py_cli_notify_state *self,
|
||||
|
||||
ok = py_tevent_req_wait_exc(py_cli_state, req);
|
||||
self->req = NULL;
|
||||
Py_DECREF(self->py_cli_state);
|
||||
self->py_cli_state = NULL;
|
||||
Py_CLEAR(self->py_cli_state);
|
||||
if (!ok) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -492,8 +492,7 @@ static void py_dcerpc_ndr_pointer_dealloc(PyObject* self)
|
||||
struct py_dcerpc_ndr_pointer *obj =
|
||||
pytalloc_get_type(self, struct py_dcerpc_ndr_pointer);
|
||||
|
||||
Py_DECREF(obj->value);
|
||||
obj->value = NULL;
|
||||
Py_CLEAR(obj->value);
|
||||
|
||||
self->ob_type->tp_free(self);
|
||||
}
|
||||
@ -512,7 +511,7 @@ static int py_dcerpc_ndr_pointer_set_value(PyObject *self, PyObject *value, void
|
||||
struct py_dcerpc_ndr_pointer *obj =
|
||||
pytalloc_get_type(self, struct py_dcerpc_ndr_pointer);
|
||||
|
||||
Py_DECREF(obj->value);
|
||||
Py_CLEAR(obj->value);
|
||||
obj->value = value;
|
||||
Py_INCREF(obj->value);
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user