diff --git a/include/evmc/helpers.h b/include/evmc/helpers.h index 9273e2b..e43cfd7 100644 --- a/include/evmc/helpers.h +++ b/include/evmc/helpers.h @@ -109,11 +109,14 @@ static inline struct evmc_result evmc_execute(struct evmc_instance* instance, /** * Releases the resources allocated to the execution result. * - * @see evmc_release_result_fn + * @param result The result object to be released. MUST NOT be NULL. + * + * @see evmc_result::release() evmc_release_result_fn */ static inline void evmc_release_result(struct evmc_result* result) { - result->release(result); + if (result->release) + result->release(result); } diff --git a/test/unittests/test_helpers.cpp b/test/unittests/test_helpers.cpp index 82d8195..504025a 100644 --- a/test/unittests/test_helpers.cpp +++ b/test/unittests/test_helpers.cpp @@ -61,3 +61,19 @@ TEST(helpers, is_zero) b.bytes[0] = 1; EXPECT_FALSE(is_zero(b)); } + +TEST(helpers, release_result) +{ + auto r1 = evmc_result{}; + evmc_release_result(&r1); + + static evmc_result r2; + static bool e; + + e = false; + r2 = evmc_result{}; + r2.release = [](const evmc_result* r) { e = r == &r2; }; + EXPECT_FALSE(e); + evmc_release_result(&r2); + EXPECT_TRUE(e); +}