Skip to content

Commit feed6f2

Browse files
committed
Missed some error handling in the C code.
1 parent 7c50d0e commit feed6f2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

TODO.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ x Tricky swapping of collector like figleaf, pycov, et al. (Don't need to do
2929
CodeParser.raw_parse.
3030
- If tracing, canonical_filename_cache overlaps with should_trace_cache. Skip
3131
canonical_filename_cache. Maybe it isn't even worth it...
32+
- Would pre-allocating line number integers make the C tracer faster?
3233

3334

3435
* Accuracy

coverage/tracer.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Tracer_record_pair(Tracer *self, int l1, int l2)
243243
static int
244244
Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
245245
{
246+
int ret = 0;
246247
PyObject * filename = NULL;
247248
PyObject * tracename = NULL;
248249

@@ -326,7 +327,10 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
326327
STATS( self->stats.errors++; )
327328
return -1;
328329
}
329-
PyDict_SetItem(self->should_trace_cache, filename, tracename);
330+
if (PyDict_SetItem(self->should_trace_cache, filename, tracename) < 0) {
331+
STATS( self->stats.errors++; )
332+
return -1;
333+
}
330334
}
331335
else {
332336
Py_INCREF(tracename);
@@ -341,8 +345,12 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
341345
STATS( self->stats.errors++; )
342346
return -1;
343347
}
344-
PyDict_SetItem(self->data, tracename, file_data);
348+
ret = PyDict_SetItem(self->data, tracename, file_data);
345349
Py_DECREF(file_data);
350+
if (ret < 0) {
351+
STATS( self->stats.errors++; )
352+
return -1;
353+
}
346354
}
347355
self->cur_file_data = file_data;
348356
SHOWLOG(self->depth, frame->f_lineno, filename, "traced");
@@ -389,8 +397,16 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
389397
else {
390398
/* Tracing lines: key is simply this_line. */
391399
PyObject * this_line = MyInt_FromLong(frame->f_lineno);
392-
PyDict_SetItem(self->cur_file_data, this_line, Py_None);
400+
if (this_line == NULL) {
401+
STATS( self->stats.errors++; )
402+
return -1;
403+
}
404+
ret = PyDict_SetItem(self->cur_file_data, this_line, Py_None);
393405
Py_DECREF(this_line);
406+
if (ret < 0) {
407+
STATS( self->stats.errors++; )
408+
return -1;
409+
}
394410
}
395411
}
396412
self->last_line = frame->f_lineno;

0 commit comments

Comments
 (0)