There are no exceptions in C (but you cannot use them in any language), so the only way mallocto signal a failure is to return a null pointer. Therefore, you should check the return value. If it is 0, the distribution failed (for some reason) and no memory was allocated - do not release anything; otherwise allocating the requested amount (*) would be successful and you would need to free the memory when it is no longer needed.
(*) : malloc size_t, , , . size * sizeof(int) unsigned size (, size), . malloc() () size,