profiler.close()
os.unlink(self.logfn)
+ def test_bad_sys_path(self):
+ import sys
+ orig_path = sys.path
+ coverage = hotshot._hotshot.coverage
+ try:
+ # verify we require a list for sys.path
+ sys.path = 'abc'
+ self.assertRaises(RuntimeError, coverage, test_support.TESTFN)
+ # verify sys.path exists
+ del sys.path
+ self.assertRaises(RuntimeError, coverage, test_support.TESTFN)
+ finally:
+ sys.path = orig_path
def test_main():
test_support.run_unittest(HotShotTestCase)
}
else if (!err) {
result = PyTuple_New(4);
+ if (result == NULL)
+ return NULL;
PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
if (s1 == NULL)
getcwd(cwdbuffer, sizeof cwdbuffer));
temp = PySys_GetObject("path");
+ if (temp == NULL || !PyList_Check(temp)) {
+ PyErr_SetString(PyExc_RuntimeError, "sys.path must be a list");
+ return -1;
+ }
len = PyList_GET_SIZE(temp);
for (i = 0; i < len; ++i) {
PyObject *item = PyList_GET_ITEM(temp, i);
{
PyObject *module, *d;
module = Py_InitModule3("_lsprof", moduleMethods, "Fast profiler");
+ if (module == NULL)
+ return;
d = PyModule_GetDict(module);
if (PyType_Ready(&PyProfiler_Type) < 0)
return;
return result;
failed:
- Py_DECREF(keys);
+ Py_XDECREF(keys);
Py_DECREF(result);
return NULL;
}
while (d < 0) {
if (len == 0) {
samps = PyTuple_New(nchannels);
+ if (samps == NULL)
+ goto exit;
for (chan = 0; chan < nchannels; chan++)
PyTuple_SetItem(samps, chan,
Py_BuildValue("(ii)",
gdict = PyDict_New();
if (gdict == NULL || (npattern = symcomp(pattern, gdict)) == NULL) {
- Py_DECREF(gdict);
+ Py_XDECREF(gdict);
Py_DECREF(pattern);
return NULL;
}