Skip to content

Commit e7cd9fe

Browse files
committed
Add test for double free (commented) and some documentation.
1 parent a28f50b commit e7cd9fe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

source/tests/metacall_test/source/metacall_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,28 @@ TEST_F(metacall_test, DefaultConstructor)
292292
};
293293

294294
EXPECT_EQ((void *)NULL, (void *)metacallfv_s(metacall_function("multiply"), corrupted_args, 2));
295+
296+
/* Testing freed value input */
297+
298+
/* TODO: The next snippet of code works but address sanitizer warns about access warning,
299+
* because in order to check the magic number we need to access the pointer to the struct.
300+
* A better solution would be, when using a custom memory pool allocator (aka object pool)
301+
* detect if the pointer is allocated or not in the object pool, so we track it without
302+
* need to access the pointer in order to read it. This can be a better improvement but
303+
* for now, this would be sufficient to catch most of the errors.
304+
*/
305+
306+
/*
307+
void *freed_args[] = {
308+
(void *)metacall_value_create_long(3L),
309+
(void *)metacall_value_create_long(5L)
310+
};
311+
312+
metacall_value_destroy(freed_args[0]);
313+
metacall_value_destroy(freed_args[1]);
314+
315+
EXPECT_EQ((void *)NULL, (void *)metacallfv_s(metacall_function("multiply"), freed_args, 2));
316+
*/
295317
}
296318
#endif /* OPTION_BUILD_LOADERS_PY */
297319

0 commit comments

Comments
 (0)