From 6432b650cc359e97f3819c8482e649b18ea5db28 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Thu, 15 May 2025 16:38:53 +0200 Subject: [PATCH] QR decode: memleak might be fixed --- c_mpos/src/quirc_decode.c | 7 ++++--- .../apps/com.example.camtest/assets/camtest.py | 15 +++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/c_mpos/src/quirc_decode.c b/c_mpos/src/quirc_decode.c index 58c8cca1..d4383e28 100644 --- a/c_mpos/src/quirc_decode.c +++ b/c_mpos/src/quirc_decode.c @@ -142,7 +142,8 @@ static mp_obj_t qrdecode_rgb565(mp_uint_t n_args, const mp_obj_t *args) { mp_obj_new_int(height) }; - mp_obj_t result = MP_OBJ_NULL; + //mp_obj_t result = MP_OBJ_NULL; + mp_obj_t result = mp_const_none; nlr_buf_t exception_handler; if (nlr_push(&exception_handler) == 0) { result = qrdecode(3, gray_args); @@ -152,8 +153,8 @@ static mp_obj_t qrdecode_rgb565(mp_uint_t n_args, const mp_obj_t *args) { } else { QRDECODE_DEBUG_PRINT("qrdecode_rgb565: Exception caught, freeing gray_buffer\n"); free(gray_buffer); - nlr_pop(); - nlr_raise(exception_handler.ret_val); + //nlr_pop(); + //nlr_raise(exception_handler.ret_val); } return result; diff --git a/internal_filesystem/apps/com.example.camtest/assets/camtest.py b/internal_filesystem/apps/com.example.camtest/assets/camtest.py index 576ef51d..696846d7 100644 --- a/internal_filesystem/apps/com.example.camtest/assets/camtest.py +++ b/internal_filesystem/apps/com.example.camtest/assets/camtest.py @@ -54,12 +54,15 @@ def qrdecode_live(): try: import qrdecode result = qrdecode.qrdecode_rgb565(current_cam_buffer, width, height) - #raise ValueError('A very specific bad thing happened.') - result = remove_bom(result) - result = print_qr_buffer(result) - print(f"QR decoding found: {result}") - status_label_text = result - stop_qr_decoding() + if not result: + status_label_text = status_label_text_searching + else: + #raise ValueError('A very specific bad thing happened.') + result = remove_bom(result) + result = print_qr_buffer(result) + print(f"QR decoding found: {result}") + status_label_text = result + stop_qr_decoding() except ValueError as e: print("QR ValueError: ", e) status_label_text = status_label_text_searching