Fix memory errors found by Alfredo with valgrind

BufferParams::setDocumentClass() deletes the old document class of the buffer
and creates a copy of the new one. Therefore, the stored layout pointers in
the paragraphs (actually only one paragraph exists) are dangling afterwards.
Resetting them before setting the document class helps here.
In the long term we need to get rid of BufferParams::setDocumentClass()
completely, this is very ugly.