Fix leaks when deleting gallery entries.