Skip to content

Commit 545b44b

Browse files
committed
Merge pull request #642 from Safety0ff/gcismarkedfix
Fix #10701 & 10838
2 parents 05d8f0b + fc3e63c commit 545b44b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/gc/gc.d

+9-2
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ struct Gcx
16471647
else
16481648
{
16491649
// we are in a B_FREE page
1650+
assert(bin == B_FREE);
16501651
return null;
16511652
}
16521653
}
@@ -2324,6 +2325,7 @@ struct Gcx
23242325
else
23252326
{
23262327
// Don't mark bits in B_FREE pages
2328+
assert(bin == B_FREE);
23272329
continue;
23282330
}
23292331

@@ -2630,7 +2632,7 @@ struct Gcx
26302632
toClear |= GCBits.BITS_1 << clearIndex;
26312633

26322634
List *list = cast(List *)p;
2633-
debug(PRINTF) printf("\tcollecting %p\n", list);
2635+
debug(COLLECT_PRINTF) printf("\tcollecting %p\n", list);
26342636
log_free(sentinel_add(list));
26352637

26362638
debug (MEMSTOMP) memset(p, 0xF3, size);
@@ -2744,11 +2746,16 @@ struct Gcx
27442746
{
27452747
biti = (offset & notbinsize[bins]) >> pool.shiftBy;
27462748
}
2747-
else
2749+
else if(bins == B_PAGEPLUS)
27482750
{
27492751
pn -= pool.bPageOffsets[pn];
27502752
biti = pn * (PAGESIZE >> pool.shiftBy);
27512753
}
2754+
else // bins == B_FREE
2755+
{
2756+
assert(bins == B_FREE);
2757+
return IsMarked.no;
2758+
}
27522759
return pool.mark.test(biti) ? IsMarked.yes : IsMarked.no;
27532760
}
27542761
return IsMarked.unknown;

src/rt/lifetime.d

+9
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ void processGCMarks(BlkInfo* cache, scope rt.tlsgc.IsMarkedDg isMarked)
421421
}
422422
}
423423

424+
unittest
425+
{
426+
import core.memory;
427+
// Bugzilla 10701 - segfault in GC
428+
ubyte[] result; result.length = 4096;
429+
GC.free(result.ptr);
430+
GC.collect();
431+
}
432+
424433
/**
425434
Get the cached block info of an interior pointer. Returns null if the
426435
interior pointer's block is not cached.

0 commit comments

Comments
 (0)