Skip to content

Commit bf3d841

Browse files
committed
Fix decompressing using qstrs after running the VM
The qstr state still pointed to qstr pools in the released MP heap.
1 parent 5126cd3 commit bf3d841

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ STATIC void stop_mp(void) {
219219
usb_background();
220220
#endif
221221

222+
// Set the qstr pool back to the const pools. The heap allocated ones will
223+
// be overwritten.
224+
qstr_reset();
225+
222226
gc_deinit();
223227
}
224228

py/qstr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ extern const qstr_pool_t MICROPY_QSTR_EXTRA_POOL;
122122
#define CONST_POOL mp_qstr_const_pool
123123
#endif
124124

125-
void qstr_init(void) {
125+
void qstr_reset(void) {
126126
MP_STATE_VM(last_pool) = (qstr_pool_t *)&CONST_POOL; // we won't modify the const_pool since it has no allocated room left
127127
MP_STATE_VM(qstr_last_chunk) = NULL;
128+
}
129+
130+
void qstr_init(void) {
131+
qstr_reset();
128132

129133
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
130134
mp_thread_mutex_init(&MP_STATE_VM(qstr_mutex));

py/qstr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ typedef struct _qstr_pool_t {
7878

7979
#define QSTR_TOTAL() (MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len)
8080

81+
void qstr_reset(void);
8182
void qstr_init(void);
8283

8384
mp_uint_t qstr_compute_hash(const byte *data, size_t len);

0 commit comments

Comments
 (0)