diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-04-05 20:31:39 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-04-05 20:31:39 -0400 |
commit | 75f469a1cec462616a071552fd28f623ebe50e6c (patch) | |
tree | fbc4c8b834414655470e683993135811b85786be /coverage/tracer.c | |
parent | 9de004a585ca0b2cf968df9514e6ba4e66f10694 (diff) | |
download | python-coveragepy-git-75f469a1cec462616a071552fd28f623ebe50e6c.tar.gz |
A technicality: if should_trace returned a non-string, it would leak.
Diffstat (limited to 'coverage/tracer.c')
-rw-r--r-- | coverage/tracer.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/coverage/tracer.c b/coverage/tracer.c index 9c079cbb..e5d1e06a 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
|