@@ -85,48 +85,78 @@ make_timezones_capi(PyObject *self, PyObject *args)
85
85
{
86
86
PyObject * offset = PyDelta_FromDSU (0 , -18000 , 0 );
87
87
PyObject * name = PyUnicode_FromString ("EST" );
88
+ if (offset == NULL || name == NULL ) {
89
+ Py_XDECREF (offset );
90
+ Py_XDECREF (name );
91
+ return NULL ;
92
+ }
88
93
89
94
PyObject * est_zone_capi = PyDateTimeAPI -> TimeZone_FromTimeZone (offset , name );
90
95
PyObject * est_zone_macro = PyTimeZone_FromOffsetAndName (offset , name );
91
96
PyObject * est_zone_macro_noname = PyTimeZone_FromOffset (offset );
92
-
93
- Py_DecRef (offset );
94
- Py_DecRef (name );
95
-
97
+ Py_DECREF (offset );
98
+ Py_DECREF (name );
99
+ if (est_zone_capi == NULL || est_zone_macro == NULL ||
100
+ est_zone_macro_noname == NULL )
101
+ {
102
+ goto error ;
103
+ }
96
104
PyObject * rv = PyTuple_New (3 );
97
105
if (rv == NULL ) {
98
- return NULL ;
106
+ goto error ;
99
107
}
100
108
101
109
PyTuple_SET_ITEM (rv , 0 , est_zone_capi );
102
110
PyTuple_SET_ITEM (rv , 1 , est_zone_macro );
103
111
PyTuple_SET_ITEM (rv , 2 , est_zone_macro_noname );
104
112
105
113
return rv ;
114
+ error :
115
+ Py_XDECREF (est_zone_capi );
116
+ Py_XDECREF (est_zone_macro );
117
+ Py_XDECREF (est_zone_macro_noname );
118
+ return NULL ;
106
119
}
107
120
108
121
static PyObject *
109
122
get_timezones_offset_zero (PyObject * self , PyObject * args )
110
123
{
111
124
PyObject * offset = PyDelta_FromDSU (0 , 0 , 0 );
112
125
PyObject * name = PyUnicode_FromString ("" );
126
+ if (offset == NULL || name == NULL ) {
127
+ Py_XDECREF (offset );
128
+ Py_XDECREF (name );
129
+ return NULL ;
130
+ }
113
131
114
132
// These two should return the UTC singleton
115
133
PyObject * utc_singleton_0 = PyTimeZone_FromOffset (offset );
116
134
PyObject * utc_singleton_1 = PyTimeZone_FromOffsetAndName (offset , NULL );
117
135
118
136
// This one will return +00:00 zone, but not the UTC singleton
119
137
PyObject * non_utc_zone = PyTimeZone_FromOffsetAndName (offset , name );
120
-
121
- Py_DecRef (offset );
122
- Py_DecRef (name );
138
+ Py_DECREF (offset );
139
+ Py_DECREF (name );
140
+ if (utc_singleton_0 == NULL || utc_singleton_1 == NULL ||
141
+ non_utc_zone == NULL )
142
+ {
143
+ goto error ;
144
+ }
123
145
124
146
PyObject * rv = PyTuple_New (3 );
147
+ if (rv == NULL ) {
148
+ goto error ;
149
+ }
125
150
PyTuple_SET_ITEM (rv , 0 , utc_singleton_0 );
126
151
PyTuple_SET_ITEM (rv , 1 , utc_singleton_1 );
127
152
PyTuple_SET_ITEM (rv , 2 , non_utc_zone );
128
153
129
154
return rv ;
155
+ error :
156
+ Py_XDECREF (utc_singleton_0 );
157
+ Py_XDECREF (utc_singleton_1 );
158
+ Py_XDECREF (non_utc_zone );
159
+ return NULL ;
130
160
}
131
161
132
162
static PyObject *
0 commit comments