From b1d8388ab85ac74f303b3384d25e805a56088a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bryon=20Gloden=2C=20CISSP=C2=AE?= Date: Tue, 26 Jul 2016 14:19:41 -0400 Subject: [PATCH 1/3] Update unity_fixture.c [../Unity-master/extras/fixture/src/unity_fixture.c:210]: (error) Memory leak: guard Found by https://github.com/bryongloden/cppcheck --- extras/fixture/src/unity_fixture.c | 1 + 1 file changed, 1 insertion(+) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 7e4d1e8..8e39876 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -207,6 +207,7 @@ void* unity_malloc(size_t size) mem = (char*)&(guard[1]); memcpy(&mem[size], end, sizeof(end)); + free(guard); return (void*)mem; } From 0737b4117fdc74a33a24080bd1f1a28069d4eb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bryon=20Gloden=2C=20CISSP=C2=AE?= Date: Tue, 26 Jul 2016 16:02:41 -0400 Subject: [PATCH 2/3] Update unity_fixture.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Free guard if UNITY_EXCLUDE_STDLIB_MALLOC is not defined. 👍 Thanks @ for the hint. --- extras/fixture/src/unity_fixture.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 8e39876..8130931 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -207,7 +207,9 @@ void* unity_malloc(size_t size) mem = (char*)&(guard[1]); memcpy(&mem[size], end, sizeof(end)); +#ifndef UNITY_EXCLUDE_STDLIB_MALLOC free(guard); +#endif return (void*)mem; } From 4fd5f79f28562ac3e627bb5b4a590aaa32317902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bryon=20Gloden=2C=20CISSP=C2=AE?= Date: Tue, 26 Jul 2016 19:41:30 -0400 Subject: [PATCH 3/3] Update unity_fixture.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorry @mvandervoord -- not your code, your repository 😁 Regarding the double free, cppcheck has a check for that too (just saying) 👍 --- extras/fixture/src/unity_fixture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 8130931..79d925e 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -207,7 +207,7 @@ void* unity_malloc(size_t size) mem = (char*)&(guard[1]); memcpy(&mem[size], end, sizeof(end)); -#ifndef UNITY_EXCLUDE_STDLIB_MALLOC +#ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ free(guard); #endif return (void*)mem;