avoid memory leak and invalid documents

See e.g. fdo54757-1.xlsx exported to ods.

Change-Id: I81fb9a18519c5770b52dfb8131211e440ad9682f