helpers: Handle results with null release() method

This commit is contained in:
Paweł Bylica 2019-05-09 21:51:42 +02:00
parent 2ca88aca07
commit 3b834de095
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
2 changed files with 21 additions and 2 deletions

View File

@ -109,11 +109,14 @@ static inline struct evmc_result evmc_execute(struct evmc_instance* instance,
/** /**
* Releases the resources allocated to the execution result. * 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) static inline void evmc_release_result(struct evmc_result* result)
{ {
result->release(result); if (result->release)
result->release(result);
} }

View File

@ -61,3 +61,19 @@ TEST(helpers, is_zero)
b.bytes[0] = 1; b.bytes[0] = 1;
EXPECT_FALSE(is_zero(b)); 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);
}