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.
Merge pull request #433 from jhnwkmn/malloc

Consistent use of NS_MALLOC, NS_FREE and NS_REALLOC