Skip to content

Commit

Permalink
Fix reference leak in result4
Browse files Browse the repository at this point in the history
Two error cases are missing a Py_XDECREF(valuestr). A password change
with an invalid old password triggers a reference leak.

Closes: https://github.com/python-ldap/python-ldap/issues/37
https://github.com/python-ldap/python-ldap/pull/38
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Nov 28, 2017
1 parent 5dcf6e8 commit 0778a20
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ l_ldap_result4( LDAPObject* self, PyObject *args )
PyObject *result_str, *retval, *pmsg, *pyctrls = 0;
int res_msgid = 0;
char *retoid = 0;
PyObject *valuestr = 0;
PyObject *valuestr = NULL;

if (!PyArg_ParseTuple( args, "|iidiii", &msgid, &all, &timeout, &add_ctrls, &add_intermediates, &add_extop ))
return NULL;
Expand Down Expand Up @@ -1071,6 +1071,7 @@ l_ldap_result4( LDAPObject* self, PyObject *args )
} else
e = "ldap_parse_result";
ldap_msgfree(msg);
Py_XDECREF(valuestr);
return LDAPerror( self->ldap, e );
}

Expand All @@ -1080,6 +1081,7 @@ l_ldap_result4( LDAPObject* self, PyObject *args )
ldap_set_option(self->ldap, LDAP_OPT_ERROR_NUMBER, &err);
LDAP_END_ALLOW_THREADS( self );
ldap_msgfree(msg);
Py_XDECREF(valuestr);
return LDAPerror(self->ldap, "LDAPControls_to_List");
}
ldap_controls_free(serverctrls);
Expand Down Expand Up @@ -1108,9 +1110,7 @@ l_ldap_result4( LDAPObject* self, PyObject *args )
Py_DECREF(pmsg);
}
}
if (valuestr) {
Py_DECREF(valuestr);
}
Py_XDECREF(valuestr);
Py_XDECREF(pyctrls);
Py_DECREF(result_str);
return retval;
Expand Down

0 comments on commit 0778a20

Please sign in to comment.