From ea2a5ffd6cfdbbaeefc1bee717bf4ade73e35689 Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Sun, 15 May 2022 00:46:15 +0530 Subject: [PATCH] fix refcount issue after ubsan pointed out error There was a comment there warning of memory faults. asan/ubsan proved it right. --- third_party/python/Python/import.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/python/Python/import.c b/third_party/python/Python/import.c index 70019b31a..4a6ae2e61 100644 --- a/third_party/python/Python/import.c +++ b/third_party/python/Python/import.c @@ -2289,12 +2289,12 @@ static PyObject *_imp_validate_bytecode_header(PyObject *module, PyObject *args, data.buf = &(buf[12]); data.len -= 12; result = PyMemoryView_FromBuffer(&data); - // TODO: figure out if refcounts are managed between data and result - + // TODO: figure out how refcounts are managed between data and result // if there is a memory fault, use the below line which copies // result = PyBytes_FromStringAndSize(&(buf[12]), data.len-12); exit: - if (data.obj) PyBuffer_Release(&data); + if (!result && data.obj) PyBuffer_Release(&data); + // if (data.obj) PyBuffer_Release(&data); return result; } PyDoc_STRVAR(_imp_validate_bytecode_header_doc,