Misc fixes

- fixed double free in pointer cache
- set some pointers to NULL after free