Commits

Ned Batchelder committed 1c8450f

A technicality: if should_trace returned a non-string, it would leak.

  • Participants
  • Parent commits 2469736

Comments (0)

Files changed (1)

File coverage/tracer.c

 
 // The Tracer type.
 
+#define MAX_STACK_DEPTH 500
+
 typedef struct {
     PyObject_HEAD
     PyObject * should_trace;
     // 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
     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;
         }
         }
 
         // 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