Skip to content
Myr

Fix crash when importing a module with errors twice (#3497)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When a module fails to parse as a library, `load_library` cached the invalid block. A second import/include of the same module would find the cached invalid block and pass it to `block_bind_library`, triggering the assertion failure. Skip caching the block when there are parse errors to avoid this problem.

authored by itchyny · committed by GitHub · parent ed3c7f2 · Browse files · 1 file+7 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−5 removed

  • other:+7 added−5 removed

1 file+7 added−5 removed

modified:src/linker.c+7 added-5 removed
364 unmodified lines
365 free(lib_origin);366 program = block_bind_self(program, OP_IS_CALL_PSEUDO);367 }368 }369 if (nerrors == 0) {369 state_idx = lib_state->ct++;370 lib_state->names = jv_mem_realloc(lib_state->names, lib_state->ct * sizeof(const char *));371 lib_state->defs = jv_mem_realloc(lib_state->defs, lib_state->ct * sizeof(block));372 lib_state->names[state_idx] = strdup(jv_string_value(lib_path));373 lib_state->defs[state_idx] = program;370 state_idx = lib_state->ct++;371 lib_state->names = jv_mem_realloc(lib_state->names, lib_state->ct * sizeof(const char *));372 lib_state->defs = jv_mem_realloc(lib_state->defs, lib_state->ct * sizeof(block));373 lib_state->names[state_idx] = strdup(jv_string_value(lib_path));374 lib_state->defs[state_idx] = program;375 }376out:377 *out_block = program;378 jv_free(lib_path);379 jv_free(data);
75 unmodified lines