malloc+memset to calloc and realloc leak fix 

Realloc good practice is to use a tmp pointer only when tested the assignment is completed.
malloc+ memset is bad practice on security and performance. Security because the params are tested for memory hazards and overflows.