summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-04-05 20:31:39 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-04-05 20:31:39 -0400
commit9712de97e1abd7b629ae17efcb46e457b749fc07 (patch)
tree11f1edb674a3529a705baade6fa6d345438e3278
parente86dc47851c9e24dfb854b43ed59cf67733daabb (diff)
downloadpython-coveragepy-9712de97e1abd7b629ae17efcb46e457b749fc07.tar.gz
A technicality: if should_trace returned a non-string, it would leak.
-rw-r--r--coverage/tracer.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/coverage/tracer.c b/coverage/tracer.c
index 9c079cb..e5d1e06 100644
--- a/coverage/tracer.c
+++ b/coverage/tracer.c
@@ -16,6 +16,8 @@
// The Tracer type.
+#define MAX_STACK_DEPTH 500
+
typedef struct {
PyObject_HEAD
PyObject * should_trace;
@@ -25,7 +27,7 @@ typedef struct {
// The index of the last-used entry in tracenames.
int depth;
// Filenames to record at each level, or NULL if not recording.
- PyObject * tracenames[300];
+ PyObject * tracenames[MAX_STACK_DEPTH];
} Tracer;
static int
@@ -69,7 +71,7 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
switch (what) {
case PyTrace_CALL: // 0
self->depth++;
- if (self->depth > sizeof(self->tracenames)/sizeof(self->tracenames[0])) {
+ if (self->depth > MAX_STACK_DEPTH) {
PyErr_SetString(PyExc_RuntimeError, "Tracer stack overflow");
return -1;
}
@@ -92,7 +94,13 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
}
// If tracename is a string, then we're supposed to trace.
- self->tracenames[self->depth] = PyString_Check(tracename) ? tracename : NULL;
+ if (PyString_Check(tracename)) {
+ self->tracenames[self->depth] = tracename;
+ }
+ else {
+ self->tracenames[self->depth] = NULL;
+ Py_DECREF(tracename);
+ }
break;
case PyTrace_RETURN: // 3