adapt repo->end in repo_empty() function
fix access to freed memory if we had to allocate a new schema when serializing a key