I don't see anything wrong.

BTW, we usually don't cast the return value of malloc (if your compiler complains then it's set for compiling C++, not C).