Skip to content

Commit c25534e

Browse files
timholyKristofferC
authored andcommitted
Fix memory error during precompilation (#44345)
Fixes #44338 (cherry picked from commit b4ea0f7)
1 parent dc8714a commit c25534e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/dump.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ static int has_backedge_to_worklist(jl_method_instance_t *mi, htable_t *visited)
272272
for (i = 0; i < n; i++) {
273273
jl_method_instance_t *be = (jl_method_instance_t*)jl_array_ptr_ref(mi->backedges, i);
274274
if (has_backedge_to_worklist(be, visited)) {
275+
bp = ptrhash_bp(visited, mi); // re-acquire since rehashing might change the location
275276
*bp = (void*)((char*)HT_NOTFOUND + 2); // found
276277
return 1;
277278
}
@@ -286,10 +287,10 @@ static size_t queue_external_mis(jl_array_t *list)
286287
{
287288
size_t i, n = 0;
288289
htable_t visited;
289-
htable_new(&visited, 0);
290290
if (list) {
291291
assert(jl_is_array(list));
292292
size_t n0 = jl_array_len(list);
293+
htable_new(&visited, n0);
293294
for (i = 0; i < n0; i++) {
294295
jl_method_instance_t *mi = (jl_method_instance_t*)jl_array_ptr_ref(list, i);
295296
assert(jl_is_method_instance(mi));
@@ -2640,7 +2641,7 @@ JL_DLLEXPORT int jl_save_incremental(const char *fname, jl_array_t *worklist)
26402641
arraylist_new(&reinit_list, 0);
26412642
htable_new(&edges_map, 0);
26422643
htable_new(&backref_table, 5000);
2643-
htable_new(&external_mis, 0);
2644+
htable_new(&external_mis, newly_inferred ? jl_array_len(newly_inferred) : 0);
26442645
ptrhash_put(&backref_table, jl_main_module, (char*)HT_NOTFOUND + 1);
26452646
backref_table_numel = 1;
26462647
jl_idtable_type = jl_base_module ? jl_get_global(jl_base_module, jl_symbol("IdDict")) : NULL;

0 commit comments

Comments
 (0)