From 9a6fa599bfb34ef77561e14051deca513936b1c5 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 14 Aug 2023 11:24:48 +0400 Subject: [PATCH] Avoid potentially accessing data after deallocation in unref spec After the last unref, derived_instance's struct data may be deallocated, so fetching its refcount field is unreliable. By first increasing the refcount, checking that unref decreases the refcount can be tested reliably. --- test/integration/generated_regress_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/integration/generated_regress_test.rb b/test/integration/generated_regress_test.rb index 3b73d0a4..ce54e643 100644 --- a/test/integration/generated_regress_test.rb +++ b/test/integration/generated_regress_test.rb @@ -1453,9 +1453,10 @@ def make_derived_instance end it "has a working method #unref" do - _(base_struct[:refcount]).must_equal 1 + derived_instance.ref + _(base_struct[:refcount]).must_equal 2 derived_instance.unref - _(base_struct[:refcount]).must_equal 0 + _(base_struct[:refcount]).must_equal 1 end end