From 3d05a10e40d4349b01e292dbc297036f8de38049 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 21 Apr 2017 11:57:22 +0200 Subject: Fix GC corruption on macOS and possibly some other OSes Marking mmap'ed memory as unneeded, leads to it being zeroed out on both Linux and Windows. Unfortunately that behavior is not defined by POSIX, so BSD based OSes (and possible others as well) do not do this. We do however rely on getting zeroed out memory whenever we allocate a new Chunk for the garbage collector. To work around this, zero out memory we deallocate on those platforms. Task-number: QTBUG-59278 Task-number: QTBUG-59977 Change-Id: Idde812db8537b63b9e9df7de41620ce0df09b6de Reviewed-by: Simon Hausmann Reviewed-by: Robin Burchell --- src/qml/memory/qv4mm.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index 27adfcb517..88912a6678 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -161,6 +161,13 @@ struct MemorySegment { size_t pageSize = WTF::pageSize(); size = (size + pageSize - 1) & ~(pageSize - 1); +#if !defined(Q_OS_LINUX) && !defined(Q_OS_WIN) + // Linux and Windows zero out pages that have been decommitted and get committed again. + // unfortunately that's not true on other OSes (e.g. BSD based ones), so zero out the + // memory before decommit, so that we can be sure that all chunks we allocate will be + // zero initialized. + memset(chunk, 0, size); +#endif pageReservation.decommit(chunk, size); } -- cgit v1.2.3