8000 gh-111178: fix UBSan failures in `Modules/_lsprof.c` by picnixz · Pull Request #129782 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/_lsprof.c #129782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
< 8000 details data-target="details-toggle.detailsTarget" data-view-component="true" class="diffbar-item details-reset details-overlay position-relative text-center">
Diff view
Diff view
Next Next commit
fix UBSan failures for ProfilerObject
  • Loading branch information
picnixz committed Jan 25, 2025
commit f9efd31ebce200fb1f65692fa4d23c981aa8ba66
24 changes: 14 additions & 10 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ typedef struct {
PyObject* missing;
} ProfilerObject;

#define _ProfilerObject_CAST(op) ((ProfilerObject *)(op))

#define POF_ENABLED 0x001
#define POF_SUBCALLS 0x002
#define POF_BUILTINS 0x004
Expand Down Expand Up @@ -919,29 +921,31 @@ _lsprof_Profiler_clear_impl(ProfilerObject *self)
}

static int
profiler_traverse(ProfilerObject *op, visitproc visit, void *arg)
profiler_traverse(PyObject *op, visitproc visit, void *arg)
{
ProfilerObject *self = _ProfilerObject_CAST(op);
Py_VISIT(Py_TYPE(op));
Py_VISIT(op->externalTimer);
Py_VISIT(self->externalTimer);
return 0;
}

static void
profiler_dealloc(ProfilerObject *op)
profiler_dealloc(PyObject *op)
{
PyObject_GC_UnTrack(op);
if (op->flags & POF_ENABLED) {
ProfilerObject *self = _ProfilerObject_CAST(op);
PyObject_GC_UnTrack(self);
if (self->flags & POF_ENABLED) {
PyThreadState *tstate = _PyThreadState_GET();
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {
PyErr_FormatUnraisable("Exception ignored when destroying _lsprof profiler");
}
}

flush_unmatched(op);
clearEntries(op);
Py_XDECREF(op->externalTimer);
PyTypeObject *tp = Py_TYPE(op);
tp->tp_free(op);
flush_unmatched(self);
clearEntries(self);
Py_XDECREF(self->externalTimer);
PyTypeObject *tp = Py_TYPE(self);
tp->tp_free(self);
Py_DECREF(tp);
}

Expand Down
0