Merge pull request #13 from TwP/set-freed-pointers-to-null

Set freed pointers to NULL and free device in cleanup.  This allows multiple calls to the cleanup function without segfault/corruption.
Merge remote-tracking branch 'jgraff/master'