The way malloc is implemented is by definition system or implementation dependent.
(A silly, but standard conforming, implementation of malloc would always fail by returning NULL; most real implementations are better than this).
Read first the behavioral specifications of malloc, realloc, free (Posix standard).