Skip to content

Commit 46a07dd

Browse files
committed
PYTHON-3959 - NULL Initialize PyObjects
NULL initialize PyObjects before calling PyErr_*
1 parent 9b9cf73 commit 46a07dd

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

bson/_cbsonmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static PyObject* datetime_from_millis(long long millis) {
279279
* micros = diff * 1000 111000
280280
* Resulting in datetime(1, 1, 1, 1, 1, 1, 111000) -- the expected result
281281
*/
282-
PyObject* datetime;
282+
PyObject* datetime = NULL;
283283
int diff = (int)(((millis % 1000) + 1000) % 1000);
284284
int microseconds = diff * 1000;
285285
Time64_T seconds = (millis - diff) / 1000;
@@ -1790,7 +1790,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
17901790
PyObject* result;
17911791
unsigned char check_keys;
17921792
unsigned char top_level = 1;
1793-
PyObject* options_obj;
1793+
PyObject* options_obj = NULL;
17941794
codec_options_t options;
17951795
buffer_t buffer;
17961796
PyObject* raw_bson_document_bytes_obj;
@@ -2620,7 +2620,7 @@ static PyObject* _cbson_element_to_dict(PyObject* self, PyObject* args) {
26202620
/* TODO: Support buffer protocol */
26212621
char* string;
26222622
PyObject* bson;
2623-
PyObject* options_obj;
2623+
PyObject* options_obj = NULL;
26242624
codec_options_t options;
26252625
unsigned position;
26262626
unsigned max;
@@ -2732,7 +2732,7 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* args) {
27322732
int32_t size;
27332733
Py_ssize_t total_size;
27342734
const char* string;
2735-
PyObject* bson;
2735+
PyObject* bson = NULL;
27362736
codec_options_t options;
27372737
PyObject* result = NULL;
27382738
PyObject* options_obj;

pymongo/_cmessagemodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ _cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
540540
PyObject* ctx = NULL;
541541
PyObject* to_publish = NULL;
542542
PyObject* result = NULL;
543-
PyObject* options_obj;
543+
PyObject* options_obj = NULL;
544544
codec_options_t options;
545545
buffer_t buffer;
546546
struct module_state *state = GETSTATE(self);
@@ -597,7 +597,7 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
597597
PyObject* ctx = NULL;
598598
PyObject* to_publish = NULL;
599599
PyObject* result = NULL;
600-
PyObject* options_obj;
600+
PyObject* options_obj = NULL;
601601
codec_options_t options;
602602
buffer_t buffer;
603603
struct module_state *state = GETSTATE(self);
@@ -873,7 +873,7 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
873873
PyObject* ctx = NULL;
874874
PyObject* to_publish = NULL;
875875
PyObject* result = NULL;
876-
PyObject* options_obj;
876+
PyObject* options_obj = NULL;
877877
codec_options_t options;
878878
buffer_t buffer;
879879
struct module_state *state = GETSTATE(self);

0 commit comments

Comments
 (0)