bug fixes, added str_ndup

Fixed bug when tracking resources for reallocated memory. Added check to
string chunks for null inputs. Added a function to duplicate a substring.