From 3f68c5e9885dc36fe332643737cdf59b80391ee0 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 10 May 2017 17:24:40 +1000 Subject: [PATCH] vfs uart tests: Avoid 1 byte heap overrun & memory leak --- components/vfs/test/test_vfs_uart.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/vfs/test/test_vfs_uart.c b/components/vfs/test/test_vfs_uart.c index 892ca527c6..2a74db61f7 100644 --- a/components/vfs/test/test_vfs_uart.c +++ b/components/vfs/test/test_vfs_uart.c @@ -50,8 +50,8 @@ TEST_CASE("can read from stdin", "[vfs]") const size_t count = 12; srand(count); - char* data = (char*) calloc(1, count * 8 + 1); - char* buf = (char*) calloc(1, count * 8 + 1); + char* data = (char*) calloc(1, count * 8 + 2); + char* buf = (char*) calloc(1, count * 8 + 2); char* p = data; for (size_t i = 0; i < count; ++i) { p += sprintf(p, "%08x", rand()); @@ -62,6 +62,9 @@ TEST_CASE("can read from stdin", "[vfs]") size_t cb = fread(buf, 1, len, stdin); TEST_ASSERT_EQUAL(len, cb); TEST_ASSERT_EQUAL_UINT8_ARRAY(data, buf, len); + + free(data); + free(buf); }