Fix memory leaks in call to SQlite database