udirt heap related bug fixes.

- fixed a number of heap bugs
- fixed a number of memory leaks