Modify to use sqlite3_free in each functions