Skip to content

Commit 127ce23

Browse files
committed
PYTHON-3959 - NULL Initialize PyObjects
Initialize all PyObjects, not just those that included in calls to PyErr_*.
1 parent 46a07dd commit 127ce23

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

bson/_cbsonmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static PyObject* _test_long_long_to_str(PyObject* self, PyObject* args) {
207207
*
208208
* Returns a new ref */
209209
static PyObject* _error(char* name) {
210-
PyObject* error;
210+
PyObject* error = NULL;
211211
PyObject* errors = PyImport_ImportModule("bson.errors");
212212
if (!errors) {
213213
return NULL;
@@ -294,7 +294,7 @@ static PyObject* datetime_from_millis(long long millis) {
294294
timeinfo.tm_sec,
295295
microseconds);
296296
if(!datetime) {
297-
PyObject *etype, *evalue, *etrace;
297+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
298298

299299
/*
300300
* Calling _error clears the error state, so fetch it first.
@@ -350,8 +350,8 @@ static PyObject* datetime_ms_from_millis(PyObject* self, long long millis){
350350
return NULL;
351351
}
352352

353-
PyObject* dt;
354-
PyObject* ll_millis;
353+
PyObject* dt = NULL;
354+
PyObject* ll_millis = NULL;
355355

356356
if (!(ll_millis = PyLong_FromLongLong(millis))){
357357
return NULL;

pymongo/_cmessagemodule.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct module_state {
3131
PyObject* _max_bson_size_str;
3232
PyObject* _max_message_size_str;
3333
PyObject* _max_write_batch_size_str;
34-
PyObject* _max_split_size_str;
34+
PyObject* _max_split_size_str;
3535
};
3636

3737
/* See comments about module initialization in _cbsonmodule.c */
@@ -45,7 +45,7 @@ struct module_state {
4545
*
4646
* Returns a new ref */
4747
static PyObject* _error(char* name) {
48-
PyObject* error;
48+
PyObject* error = NULL;
4949
PyObject* errors = PyImport_ImportModule("pymongo.errors");
5050
if (!errors) {
5151
return NULL;
@@ -75,9 +75,9 @@ static PyObject* _cbson_query_message(PyObject* self, PyObject* args) {
7575
int begin, cur_size, max_size = 0;
7676
int num_to_skip;
7777
int num_to_return;
78-
PyObject* query;
79-
PyObject* field_selector;
80-
PyObject* options_obj;
78+
PyObject* query = NULL;
79+
PyObject* field_selector = NULL;
80+
PyObject* options_obj = NULL;
8181
codec_options_t options;
8282
buffer_t buffer = NULL;
8383
int length_location, message_length;
@@ -221,12 +221,12 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
221221
/* NOTE just using a random number as the request_id */
222222
int request_id = rand();
223223
unsigned int flags;
224-
PyObject* command;
224+
PyObject* command = NULL;
225225
char* identifier = NULL;
226226
Py_ssize_t identifier_length = 0;
227-
PyObject* docs;
228-
PyObject* doc;
229-
PyObject* options_obj;
227+
PyObject* docs = NULL;
228+
PyObject* doc = NULL;
229+
PyObject* options_obj = NULL;
230230
codec_options_t options;
231231
buffer_t buffer = NULL;
232232
int length_location, message_length;
@@ -535,8 +535,8 @@ static PyObject*
535535
_cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
536536
unsigned char op;
537537
unsigned char ack;
538-
PyObject* command;
539-
PyObject* docs;
538+
PyObject* command = NULL;
539+
PyObject* docs = NULL;
540540
PyObject* ctx = NULL;
541541
PyObject* to_publish = NULL;
542542
PyObject* result = NULL;
@@ -592,8 +592,8 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
592592
unsigned char ack;
593593
int request_id;
594594
int position;
595-
PyObject* command;
596-
PyObject* docs;
595+
PyObject* command = NULL;
596+
PyObject* docs = NULL;
597597
PyObject* ctx = NULL;
598598
PyObject* to_publish = NULL;
599599
PyObject* result = NULL;
@@ -868,8 +868,8 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
868868
char *ns = NULL;
869869
unsigned char op;
870870
Py_ssize_t ns_len;
871-
PyObject* command;
872-
PyObject* docs;
871+
PyObject* command = NULL;
872+
PyObject* docs = NULL;
873873
PyObject* ctx = NULL;
874874
PyObject* to_publish = NULL;
875875
PyObject* result = NULL;

0 commit comments

Comments
 (0)