Fixed memory leaks properly

There is now two ways of preparing statements. The new prepare function
is for step functions needing a new statement on every run. The
prepare_or_reset function has been redone. It is meant for functions
preparing a statement statically  once, and then reusing it through out
the program. It saves a pointer to the allocated statement in a new
global linked list called the prepcache. All statements saved there are
finalized atexit by close_db.