# HG changeset patch # User Augie Fackler # Date 2015-01-23 20:30:21 # Node ID 5fb44983a6963c9c3ad595346f80d03c76393d15 # Parent fefa5f2a1730acac2300e1af756cc913270eb0ca parsers: don't leak references to sys et al in check_python_version Found with cpychecker. diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -2267,8 +2267,16 @@ static void module_init(PyObject *mod) static int check_python_version(void) { - PyObject *sys = PyImport_ImportModule("sys"); - long hexversion = PyInt_AsLong(PyObject_GetAttrString(sys, "hexversion")); + PyObject *sys = PyImport_ImportModule("sys"), *ver; + long hexversion; + if (!sys) + return -1; + ver = PyObject_GetAttrString(sys, "hexversion"); + Py_DECREF(sys); + if (!ver) + return -1; + hexversion = PyInt_AsLong(ver); + Py_DECREF(ver); /* sys.hexversion is a 32-bit number by default, so the -1 case * should only occur in unusual circumstances (e.g. if sys.hexversion * is manually set to an invalid value). */