[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Resolve XXXXs where possible; clear small memory leak i...



Update of /home/minion/cvsroot/src/minion/src
In directory moria.seul.org:/tmp/cvs-serv28031/src

Modified Files:
	crypt.c main.c tls.c 
Log Message:
Resolve XXXXs where possible; clear small memory leak in c code.


Index: crypt.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/crypt.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- crypt.c	6 Aug 2002 16:09:21 -0000	1.10
+++ crypt.c	19 Aug 2002 20:27:02 -0000	1.11
@@ -708,7 +708,7 @@
 }
 
 static const char mm_RSA_Type__doc__[] = 
-  "XXXX";
+  "An RSA key.  May be public or private.";
  
 PyTypeObject mm_RSA_Type = {
 	PyObject_HEAD_INIT(&PyType_Type)
@@ -888,7 +888,7 @@
 	char *filename, *cn;
 	PyObject *_rsa;
 	/* XXXX Python wants to write into longs.  C wants time_t.  We should
-	 * XXXX check somewhere to be sure that we can case long to time_t
+	 * XXXX check somewhere to be sure that we can cast long to time_t
 	 * XXXX without ill effects.
 	 */
 	long start_time, end_time;

Index: main.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- main.c	25 Jul 2002 15:52:57 -0000	1.6
+++ main.c	19 Aug 2002 20:27:02 -0000	1.7
@@ -55,19 +55,23 @@
 	PyObject *s, *exc_d;
 	if (!(s = PyString_FromString(doc)))
 		return 1;
-	if (!(exc_d = PyDict_New()))
-		return 1; /* XXXX FREE */
+	if (!(exc_d = PyDict_New())) {
+		Py_DECREF(s);
+		return 1;
+	}
 	if (PyDict_SetItemString(exc_d, "__doc__", s)<0) {
-		/* XXXX FREE */ 
+		Py_DECREF(s); Py_DECREF(exc_d);
 		return 1;
 	}
 	*exception = PyErr_NewException(longName, PyExc_Exception, exc_d);
 	if (! *exception) {
-		/* XXXX FREE */
+		Py_DECREF(s); Py_DECREF(exc_d);
 		return 1;
 	}
-	if (PyDict_SetItemString(module_dict,itemString,*exception) < 0)
+	if (PyDict_SetItemString(module_dict,itemString,*exception) < 0) {
+		Py_DECREF(s); Py_DECREF(exc_d); Py_DECREF(*exception);
 		return 1;
+	}
 
 	return 0;
 }

Index: tls.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/tls.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- tls.c	6 Aug 2002 16:09:21 -0000	1.7
+++ tls.c	19 Aug 2002 20:27:02 -0000	1.8
@@ -110,7 +110,7 @@
 	mm_TLSContext *result;
 	BIO *bio;
 	RSA *_rsa = NULL;
-	EVP_PKEY *pkey = NULL; /* Leaked? ???? */
+	EVP_PKEY *pkey = NULL;
 	
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|sO!s:TLSContext_new", 
 					 kwlist,
@@ -143,6 +143,7 @@
 			EVP_PKEY_free(pkey);
 			SSL_CTX_free(ctx); mm_SSL_ERR(0); return NULL;
 		}
+		EVP_PKEY_free(pkey);
 	} 
 
 	if (dhfile) {
@@ -463,17 +464,6 @@
 	return Py_None;
 } 
 
-#if 0
-static char mm_TLSSock_renegotiate__doc__[] = "XXXX";
-
-static PyObject*
-mm_TLSSock_renegotiate(PyObject *self, PyObject *args, PyObject *kwargs)
-{
-	
-	
-} 
-#endif
-
 static char mm_TLSSock_fileno__doc__[] = 
     "tlssock.fileno()\n\n"
     "Returns the integer filehandle underlying this TLS socket.\n";
@@ -507,15 +497,16 @@
 	
 	ssl = ((mm_TLSSock*)self)->ssl;
 	if (!(cert = SSL_get_peer_certificate(ssl))) {
-		mm_SSL_ERR(0); return NULL; /* ???? */
+		mm_SSL_ERR(0); return NULL;
 	}
 	pkey = X509_get_pubkey(cert);
-	/* ???? free? leak? */
-	if (!(rsa = EVP_PKEY_get1_RSA(pkey))) 
-		return NULL; /* XXXX */
+	if (!(rsa = EVP_PKEY_get1_RSA(pkey))) {
+		EVP_PKEY_free(pkey); mm_SSL_ERR(0); return NULL; 
+	}
+	EVP_PKEY_free(pkey);
 	
 	if (!(result = PyObject_New(mm_RSA, &mm_RSA_Type))) {
-		PyErr_NoMemory(); return NULL; 
+		RSA_free(rsa); PyErr_NoMemory(); return NULL;
 	}
 	result->rsa = rsa;