From a191144b7ab7bcbcbea34c90225f3e5351ef5a39 Mon Sep 17 00:00:00 2001 From: Parshintsev Anatoly Date: Tue, 30 Sep 2025 22:01:59 +0300 Subject: [PATCH] Get rid of leaking pointers in examples for custom extention Building of spike-based simulator with memory sanitizer reports leaking pointers if custom extension are used. This is because existing facilities do not have a proper destructor procedure, so the objects representing custom extentions are leaked. This commit implements quick-and-dirty fix for the problem. --- ci-tests/custom-csr.cc | 2 +- ci-tests/test-customext.cc | 2 +- customext/cflush.cc | 2 +- customext/dummy_rocc.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci-tests/custom-csr.cc b/ci-tests/custom-csr.cc index 857c9c32..89b0149b 100644 --- a/ci-tests/custom-csr.cc +++ b/ci-tests/custom-csr.cc @@ -37,7 +37,7 @@ struct xdummycsr_t : public extension_t { } }; -REGISTER_EXTENSION(dummycsr, []() { return new xdummycsr_t; }) +REGISTER_EXTENSION(dummycsr, []() { static xdummycsr_t ext; return &ext; }) // Copied from spike main. // TODO: This should really be provided in libriscv diff --git a/ci-tests/test-customext.cc b/ci-tests/test-customext.cc index 77c739fa..90cdb35a 100644 --- a/ci-tests/test-customext.cc +++ b/ci-tests/test-customext.cc @@ -46,7 +46,7 @@ struct xslliuw_dummy_t : public extension_t { } }; -REGISTER_EXTENSION(dummyslliuw, []() { return new xslliuw_dummy_t; }) +REGISTER_EXTENSION(dummyslliuw, []() { static xslliuw_dummy_t ext; return &ext; }) // Copied from spike main. // TODO: This should really be provided in libriscv diff --git a/customext/cflush.cc b/customext/cflush.cc index c090e884..5a9d2793 100644 --- a/customext/cflush.cc +++ b/customext/cflush.cc @@ -40,4 +40,4 @@ class cflush_t : public extension_t } }; -REGISTER_EXTENSION(cflush, []() { return new cflush_t; }) +REGISTER_EXTENSION(cflush, []() { static cflush_t ext; return &ext; }) diff --git a/customext/dummy_rocc.cc b/customext/dummy_rocc.cc index 66698873..bc239394 100644 --- a/customext/dummy_rocc.cc +++ b/customext/dummy_rocc.cc @@ -44,4 +44,4 @@ class dummy_rocc_t : public rocc_t reg_t acc[num_acc]; }; -REGISTER_EXTENSION(dummy_rocc, []() { return new dummy_rocc_t; }) +REGISTER_EXTENSION(dummy_rocc, []() { static dummy_rocc_t ext; return &ext; })