From 75b7a03db68211ae68a9c01386472363dad69639 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Sat, 21 Dec 2024 02:16:05 +0100 Subject: [PATCH] Add a crash condition if on _copy_on_write the backing reference count is 0. --- core/templates/cowdata.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h index dbbb1e6b540f..3e463a81efca 100644 --- a/core/templates/cowdata.h +++ b/core/templates/cowdata.h @@ -296,6 +296,8 @@ typename CowData::USize CowData::_copy_on_write() { SafeNumeric *refc = _get_refcount(); USize rc = refc->get(); + CRASH_COND_MSG(rc == 0, "Reference count was 0 at the time of fork."); + if (unlikely(rc > 1)) { /* in use by more than me */ USize current_size = *_get_size();