[Python-checkins] CVS: python/dist/src/Python exceptions.c,1.14,1.15

Barry Warsaw python-dev@python.org
Wed, 16 Aug 2000 12:43:19 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv31249

Modified Files:
	exceptions.c 
Log Message:
SyntaxError__str__(): Fix two memory problems discovered by Insure.
First, the allocated buffer was never freed after using it to create
the PyString object.  Second, it was possible that have_filename would
be false (meaning that filename was not a PyString object), but that
the code would still try to PyString_GET_SIZE() it.


Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** exceptions.c	2000/08/15 16:20:36	1.14
--- exceptions.c	2000/08/16 19:43:17	1.15
***************
*** 776,784 ****
  	char *buffer = NULL;
  
! 	if (filename = PyObject_GetAttrString(self, "filename"))
  	    have_filename = PyString_Check(filename);
  	else
  	    PyErr_Clear();
! 	if (lineno = PyObject_GetAttrString(self, "lineno"))
  	    have_lineno = PyInt_Check(lineno);
  	else
--- 776,785 ----
  	char *buffer = NULL;
  
! 	if ((filename = PyObject_GetAttrString(self, "filename")) != NULL)
  	    have_filename = PyString_Check(filename);
  	else
  	    PyErr_Clear();
! 
! 	if ((lineno = PyObject_GetAttrString(self, "lineno")) != NULL)
  	    have_lineno = PyInt_Check(lineno);
  	else
***************
*** 786,791 ****
  
  	if (have_filename || have_lineno) {
! 	    int bufsize = (PyString_GET_SIZE(str) + 64 +
! 			   PyString_GET_SIZE(filename));
  
  	    buffer = PyMem_Malloc(bufsize);
--- 787,793 ----
  
  	if (have_filename || have_lineno) {
! 	    int bufsize = PyString_GET_SIZE(str) + 64;
! 	    if (have_filename)
! 		bufsize += PyString_GET_SIZE(filename);
  
  	    buffer = PyMem_Malloc(bufsize);
***************
*** 804,808 ****
--- 806,813 ----
  			    PyString_AS_STRING(str),
  			    PyInt_AsLong(lineno));
+ 
  		result = PyString_FromString(buffer);
+ 		PyMem_FREE(buffer);
+ 
  		if (result == NULL)
  		    result = str;