Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.

This commit is contained in:
Hirokazu Yamamoto 2009-03-03 07:49:01 +00:00
parent 45ed72ddaf
commit 8404749e4b
4 changed files with 38 additions and 8 deletions

View File

@ -526,13 +526,18 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
if ((new = newMD5object()) == NULL)
if ((new = newMD5object()) == NULL) {
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
md5_init(&new->hash_state);
if (PyErr_Occurred()) {
Py_DECREF(new);
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
if (data_obj) {

View File

@ -502,13 +502,18 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
if ((new = newSHA1object()) == NULL)
if ((new = newSHA1object()) == NULL) {
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
sha1_init(&new->hash_state);
if (PyErr_Occurred()) {
Py_DECREF(new);
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
if (data_obj) {

View File

@ -629,13 +629,18 @@ SHA256_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
if ((new = newSHA256object()) == NULL)
if ((new = newSHA256object()) == NULL) {
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
sha_init(new);
if (PyErr_Occurred()) {
Py_DECREF(new);
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
if (data_obj) {
@ -665,13 +670,18 @@ SHA224_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
if ((new = newSHA224object()) == NULL)
if ((new = newSHA224object()) == NULL) {
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
sha224_init(new);
if (PyErr_Occurred()) {
Py_DECREF(new);
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
if (data_obj) {

View File

@ -695,13 +695,18 @@ SHA512_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
if ((new = newSHA512object()) == NULL)
if ((new = newSHA512object()) == NULL) {
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
sha512_init(new);
if (PyErr_Occurred()) {
Py_DECREF(new);
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
if (data_obj) {
@ -731,13 +736,18 @@ SHA384_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
if ((new = newSHA384object()) == NULL)
if ((new = newSHA384object()) == NULL) {
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
sha384_init(new);
if (PyErr_Occurred()) {
Py_DECREF(new);
if (data_obj)
PyBuffer_Release(&buf);
return NULL;
}
if (data_obj) {