Implement exit handlers

This commit ensures we always perform a cleanup on exit, closing any opened
backend modules and free the hashmaps. We also now store the destroy
function globally so that we can call it in iteration using destroy_module.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>