Added free_database function

Moved the freeing of the malloc'd parts of the database added two commits ago to its own function.