Fix multiple calls into the cpuminer native code

This resolves the majority of the memory leaks and crashes caused by making
sequential calls to the main cpu miner function without reloading the
library.