Use calloc instead of malloc + memset(0)
Check for allocation failures and handle them.