1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-25 17:31:36 +01:00

Merge pull request #136 from algernon/h/fixture/unity_free-NULL-safety

unity_fixture: Make unity_free() NULL-safe
This commit is contained in:
Mark VanderVoord
2015-10-06 06:50:52 -04:00
3 changed files with 14 additions and 1 deletions

View File

@@ -227,7 +227,14 @@ static void release_memory(void * mem)
void unity_free(void * mem)
{
int overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0;
int overrun;
if (mem == NULL)
{
return;
}
overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0;
release_memory(mem);
if (overrun)
{

View File

@@ -132,6 +132,11 @@ TEST(UnityFixture, PointerSet)
TEST_ASSERT_POINTERS_EQUAL(&c2, p2);
}
TEST(UnityFixture, FreeNULLSafety)
{
unity_free(NULL);
}
//------------------------------------------------------------
TEST_GROUP(UnityCommandOptions);

View File

@@ -18,6 +18,7 @@ TEST_GROUP_RUNNER(UnityFixture)
RUN_TEST_CASE(UnityFixture, ReallocSizeZeroFreesMemAndReturnsNullPointer);
RUN_TEST_CASE(UnityFixture, CallocFillsWithZero);
RUN_TEST_CASE(UnityFixture, PointerSet);
RUN_TEST_CASE(UnityFixture, FreeNULLSafety);
}
TEST_GROUP_RUNNER(UnityCommandOptions)