ENH: Fix memory leaks identified by Valgrind.

While incorporating DCMTK into the Slicer package
valgrind identified attempts to free memory
multiple times.  This patch provides
check to determine when memory needs to be
released, and only make the memory delete
calls if the pointer is not NULL.