1*4882a593Smuzhiyun[PATCH] deallocate the conversation response only in case of error 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunFixes https://bugzilla.redhat.com/show_bug.cgi?id=679714 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunDownloaded from: 6*4882a593Smuzhiyunhttp://pkgs.fedoraproject.org/cgit/PyPAM.git/plain/PyPAM-0.5.0-nofree.patch 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunSigned-off-by: Peter Korsgaard <peter@korsgaard.com> 9*4882a593Smuzhiyundiff --git a/PAMmodule.c b/PAMmodule.c 10*4882a593Smuzhiyunindex 03cb799..a7ff8a5 100644 11*4882a593Smuzhiyun--- a/PAMmodule.c 12*4882a593Smuzhiyun+++ b/PAMmodule.c 13*4882a593Smuzhiyun@@ -24,8 +24,6 @@ typedef struct { 14*4882a593Smuzhiyun char *service; 15*4882a593Smuzhiyun char *user; 16*4882a593Smuzhiyun PyObject *callback; 17*4882a593Smuzhiyun- struct pam_response *response_data; 18*4882a593Smuzhiyun- int response_len; 19*4882a593Smuzhiyun PyObject *user_data; 20*4882a593Smuzhiyun void *dlh1, *dlh2; 21*4882a593Smuzhiyun } PyPAMObject; 22*4882a593Smuzhiyun@@ -54,15 +52,6 @@ static int PyPAM_conv(int num_msg, const struct pam_message **msg, 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun Py_INCREF(self); 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun- if (NULL != self->response_data) { 27*4882a593Smuzhiyun- for (int i = 0; i < self->response_len; i++) { 28*4882a593Smuzhiyun- free(self->response_data[0].resp); 29*4882a593Smuzhiyun- } 30*4882a593Smuzhiyun- free(self->response_data); 31*4882a593Smuzhiyun- self->response_data = NULL; 32*4882a593Smuzhiyun- self->response_len = 0; 33*4882a593Smuzhiyun- } 34*4882a593Smuzhiyun- 35*4882a593Smuzhiyun PyObject* msgList = PyList_New(num_msg); 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun for (int i = 0; i < num_msg; i++) { 38*4882a593Smuzhiyun@@ -92,6 +81,10 @@ static int PyPAM_conv(int num_msg, const struct pam_message **msg, 39*4882a593Smuzhiyun char* resp_text; 40*4882a593Smuzhiyun int resp_retcode = 0; 41*4882a593Smuzhiyun if (!PyArg_ParseTuple(respTuple, "si", &resp_text, &resp_retcode)) { 42*4882a593Smuzhiyun+ while (i > 0) { 43*4882a593Smuzhiyun+ free((--spr)->resp); 44*4882a593Smuzhiyun+ --i; 45*4882a593Smuzhiyun+ } 46*4882a593Smuzhiyun free(*resp); 47*4882a593Smuzhiyun Py_DECREF(respList); 48*4882a593Smuzhiyun return PAM_CONV_ERR; 49*4882a593Smuzhiyun@@ -100,10 +93,6 @@ static int PyPAM_conv(int num_msg, const struct pam_message **msg, 50*4882a593Smuzhiyun spr->resp_retcode = resp_retcode; 51*4882a593Smuzhiyun Py_DECREF(respTuple); 52*4882a593Smuzhiyun } 53*4882a593Smuzhiyun- 54*4882a593Smuzhiyun- // Save this so we can free it later. 55*4882a593Smuzhiyun- self->response_data = *resp; 56*4882a593Smuzhiyun- self->response_len = PyList_Size(respList); 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun Py_DECREF(respList); 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun@@ -144,8 +133,6 @@ static PyObject * PyPAM_pam(PyObject *self, PyObject *args) 61*4882a593Smuzhiyun p->user = NULL; 62*4882a593Smuzhiyun Py_INCREF(Py_None); 63*4882a593Smuzhiyun p->callback = Py_None; 64*4882a593Smuzhiyun- p->response_data = NULL; 65*4882a593Smuzhiyun- p->response_len = 0; 66*4882a593Smuzhiyun Py_INCREF(Py_None); 67*4882a593Smuzhiyun p->user_data = Py_None; 68*4882a593Smuzhiyun 69