From bdeb73fa38787af6728f7d01c0f6c0ae73d38b42 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 8 Jun 2017 01:59:46 +0200 Subject: [PATCH] Correctly deal with simcall returning a intrusive_ptr of nullptr --- src/simix/popping_private.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/simix/popping_private.h b/src/simix/popping_private.h index 934565c128..90ac87f707 100644 --- a/src/simix/popping_private.h +++ b/src/simix/popping_private.h @@ -144,13 +144,17 @@ template inline T* unmarshal_raw(type, u_smx_scalar const& simcall template inline void marshal(type>, u_smx_scalar& simcall, boost::intrusive_ptr value) { - intrusive_ptr_add_ref(&*value); - simcall.dp = static_cast(&*value); + if (value.get() == nullptr) { // Sometimes we return nullptr in an intrusive_ptr... + simcall.dp = nullptr; + } else { + intrusive_ptr_add_ref(&*value); + simcall.dp = static_cast(&*value); + } } template inline boost::intrusive_ptr unmarshal(type>, u_smx_scalar const& simcall) { + // refcount was already increased during the marshaling, thus the "false" as last argument boost::intrusive_ptr res = boost::intrusive_ptr(static_cast(simcall.dp), false); - // intrusive_ptr_release(&*res); return res; } template inline T* unmarshal_raw(type>, u_smx_scalar const& simcall) -- 2.20.1