Consistent use of NS_MALLOC, NS_FREE and NS_REALLOC

malloc(), free() and realloc() were used in a number of places.
Added NS_CALLOC as well.