From ac1ca57a17184fdc5b0ef104143e92bbe5ce9514 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 12 Nov 2021 18:32:44 +0530 Subject: [PATCH] fix traceback object init --- py/objexcept.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/py/objexcept.c b/py/objexcept.c index b8d7692b18..1dd72db42b 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -553,7 +553,6 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs mp_obj_exception_t *self = get_native_exception(self_in); // Try to allocate memory for the traceback, with fallback to emergency traceback object - if (self->traceback == NULL || self->traceback == (mp_obj_traceback_t *)&mp_const_empty_traceback_obj) { self->traceback = m_new_obj_maybe(mp_obj_traceback_t); if (self->traceback == NULL) { @@ -561,9 +560,11 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs } } - // append this traceback info to traceback data - // if memory allocation fails (eg because gc is locked), just return + // populate traceback object + *self->traceback = mp_const_empty_traceback_obj; + // append the provided traceback info to traceback data + // if memory allocation fails (eg because gc is locked), just return if (self->traceback->data == NULL) { self->traceback->data = m_new_maybe(size_t, TRACEBACK_ENTRY_LEN); if (self->traceback->data == NULL) {