[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Python ceval.c,2.216,2.217 sysmodule.c,2.80,2.81

Greg Stein gstein@lyra.org
Thu, 11 Jan 2001 01:18:44 -0800


On Wed, Jan 10, 2001 at 09:41:29PM -0800, Moshe Zadka wrote:
> Update of /cvsroot/python/python/dist/src/Python
> In directory usw-pr-cvs1:/tmp/cvs-serv21213/Python
> 
> Modified Files:
> 	ceval.c sysmodule.c
>...
> --- 1246,1269 ----
>   		case PRINT_EXPR:
>   			v = POP();
> ! 			w = PySys_GetObject("displayhook");
> ! 			if (w == NULL) {
> ! 				PyErr_SetString(PyExc_RuntimeError,
> ! 						"lost sys.displayhook");
> ! 				err = -1;
>   			}
> + 			if (err == 0) {
> + 				x = Py_BuildValue("(O)", v);
> + 				if (x == NULL)
> + 					err = -1;
> + 			}
> + 			if (err == 0) {
> + 				w = PyEval_CallObject(w, x);
> + 				if (w == NULL)
> + 					err = -1;
> + 			}
>   			Py_DECREF(v);
> + 			Py_XDECREF(x);

x was never initialized to NULL. In fact, the loop sets it to Py_None. If
you get an error in the initial "w" setup case, then you could erroneously
decref None.

Further, there is no DECREF for the CallObject result ("w"). But watch out:
you don't want to DECREF the PySys_GetObject result (that is a borrowed
reference).

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/