@@ -169,8 +169,14 @@ l_ldap_dn2str(PyObject *unused, PyObject *args)
169
169
struct berval str;
170
170
LDAPDN dn = NULL;
171
171
LDAPRDN rdn = NULL;
172
+ LDAPAVA *ava = NULL;
172
173
int flags = 0;
173
- PyObject *result = NULL, *tmp = NULL, *dn_list = NULL;
174
+
175
+ PyObject *result = NULL, *tmp, *dn_list;
176
+ PyObject *iter, *inext, *iiter, *next;
177
+ PyObject *name, *value, *encoding;
178
+
179
+ Py_ssize_t nrdns, navas;
174
180
int res, i, j;
175
181
char *type_error_message = "expected List[List[Tuple[str, str, int]]]";
176
182
@@ -185,13 +191,13 @@ l_ldap_dn2str(PyObject *unused, PyObject *args)
185
191
Py_XDECREF(args);
186
192
Py_INCREF(dn_list);
187
193
188
- PyObject *iter = PyObject_GetIter(dn_list);
194
+ *iter = PyObject_GetIter(dn_list);
189
195
if (!iter) {
190
196
PyErr_SetString(PyExc_TypeError, type_error_message);
191
197
goto failed;
192
198
}
193
199
194
- Py_ssize_t nrdns = PyObject_Length(dn_list);
200
+ nrdns = PyObject_Length(dn_list);
195
201
if (nrdns == -1) {
196
202
// can't happen
197
203
goto failed;
@@ -200,7 +206,7 @@ l_ldap_dn2str(PyObject *unused, PyObject *args)
200
206
201
207
i = 0;
202
208
while (1) {
203
- PyObject *inext = PyIter_Next(iter);
209
+ *inext = PyIter_Next(iter);
204
210
if (!inext) {
205
211
break;
206
212
}
@@ -215,14 +221,14 @@ l_ldap_dn2str(PyObject *unused, PyObject *args)
215
221
goto failed;
216
222
}
217
223
218
- PyObject *iiter = PyObject_GetIter(inext);
224
+ *iiter = PyObject_GetIter(inext);
219
225
220
- Py_ssize_t navas = PyObject_Length(inext);
226
+ navas = PyObject_Length(inext);
221
227
rdn = malloc(sizeof(LDAPRDN) * (navas + 1));
222
228
223
229
j = 0;
224
230
while (1) {
225
- PyObject *next = PyIter_Next(iiter);
231
+ *next = PyIter_Next(iiter);
226
232
if (!next) {
227
233
break;
228
234
}
@@ -238,8 +244,6 @@ l_ldap_dn2str(PyObject *unused, PyObject *args)
238
244
goto failed;
239
245
}
240
246
241
- PyObject *name, *value, *encoding;
242
-
243
247
name = PyTuple_GetItem(next, 0);
244
248
value = PyTuple_GetItem(next, 1);
245
249
encoding = PyTuple_GetItem(next, 2);
@@ -255,7 +259,7 @@ l_ldap_dn2str(PyObject *unused, PyObject *args)
255
259
goto failed;
256
260
}
257
261
258
- LDAPAVA *ava = malloc(sizeof(LDAPAVA));
262
+ *ava = malloc(sizeof(LDAPAVA));
259
263
260
264
ava->la_attr.bv_val = (char *) PyUnicode_AsUTF8AndSize(name, (long int*) &ava->la_attr.bv_len);
261
265
ava->la_value.bv_val = (char *) PyUnicode_AsUTF8AndSize(value, (long int*) &ava->la_value.bv_len);
0 commit comments