From add6a30766284c89e633476b1379a46fd4ad964a Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 29 Mar 2024 10:09:29 -0700 Subject: [PATCH] PYTHON-4285 Fix PyModule_GetState check (#1565) --- bson/_cbsonmodule.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 3129a1059..3b3aecc44 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -862,20 +862,21 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer, const codec_options_t* options, unsigned char in_custom_call, unsigned char in_fallback_call) { - struct module_state *state = GETSTATE(self); PyObject* new_value = NULL; int retval; int is_list; + long type; + struct module_state *state = GETSTATE(self); + if (!state) { + return 0; + } /* * Use _type_marker attribute instead of PyObject_IsInstance for better perf. */ - long type = _type_marker(value, state->_type_marker_str); + type = _type_marker(value, state->_type_marker_str); if (type < 0) { return 0; } - if (!state) { - return 0; - } switch (type) { case 5: