Commit e5daa547 authored by Juergen Kosel's avatar Juergen Kosel

Allow to call free(NULL) as it is allowed by standard

The function myfree() is used as a replacement for free().
Therefore it must not cause any failure, if someone calls myfree(NULL).
Signed-off-by: 's avatarJuergen Kosel <juergen.kosel@softing.com>
parent 4440ab7e
...@@ -247,10 +247,13 @@ static int Internal_heap_unlink(char* file, int line, void* p) ...@@ -247,10 +247,13 @@ static int Internal_heap_unlink(char* file, int line, void* p)
*/ */
void myfree(char* file, int line, void* p) void myfree(char* file, int line, void* p)
{ {
Thread_lock_mutex(heap_mutex); if (p) /* it is legal und usual to call free(NULL) */
if (Internal_heap_unlink(file, line, p)) {
free(((int*)p)-1); Thread_lock_mutex(heap_mutex);
Thread_unlock_mutex(heap_mutex); if (Internal_heap_unlink(file, line, p))
free(((int*)p)-1);
Thread_unlock_mutex(heap_mutex);
}
} }
...@@ -479,3 +482,8 @@ int main(int argc, char *argv[]) ...@@ -479,3 +482,8 @@ int main(int argc, char *argv[])
} }
#endif /* HEAP_UNIT_TESTS */ #endif /* HEAP_UNIT_TESTS */
/* Local Variables: */
/* indent-tabs-mode: t */
/* c-basic-offset: 8 */
/* End: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment