[Python-checkins] r70127 - in python/branches/py3k/Modules: md5module.c sha1module.c sha256module.c sha512module.c

hirokazu.yamamoto python-checkins at python.org
Tue Mar 3 08:49:03 CET 2009


Author: hirokazu.yamamoto
Date: Tue Mar  3 08:49:01 2009
New Revision: 70127

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

Modified:
   python/branches/py3k/Modules/md5module.c
   python/branches/py3k/Modules/sha1module.c
   python/branches/py3k/Modules/sha256module.c
   python/branches/py3k/Modules/sha512module.c

Modified: python/branches/py3k/Modules/md5module.c
==============================================================================
--- python/branches/py3k/Modules/md5module.c	(original)
+++ python/branches/py3k/Modules/md5module.c	Tue Mar  3 08:49:01 2009
@@ -526,18 +526,23 @@
     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) {
         md5_process(&new->hash_state, buf.buf, buf.len);
-	PyBuffer_Release(&buf);
+        PyBuffer_Release(&buf);
     }
 
     return (PyObject *)new;

Modified: python/branches/py3k/Modules/sha1module.c
==============================================================================
--- python/branches/py3k/Modules/sha1module.c	(original)
+++ python/branches/py3k/Modules/sha1module.c	Tue Mar  3 08:49:01 2009
@@ -502,18 +502,23 @@
     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) {
         sha1_process(&new->hash_state, buf.buf, buf.len);
-	PyBuffer_Release(&buf);
+        PyBuffer_Release(&buf);
     }
 
     return (PyObject *)new;

Modified: python/branches/py3k/Modules/sha256module.c
==============================================================================
--- python/branches/py3k/Modules/sha256module.c	(original)
+++ python/branches/py3k/Modules/sha256module.c	Tue Mar  3 08:49:01 2009
@@ -629,13 +629,18 @@
     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 @@
     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) {

Modified: python/branches/py3k/Modules/sha512module.c
==============================================================================
--- python/branches/py3k/Modules/sha512module.c	(original)
+++ python/branches/py3k/Modules/sha512module.c	Tue Mar  3 08:49:01 2009
@@ -695,13 +695,18 @@
     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 @@
     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) {


More information about the Python-checkins mailing list