Fix memory leaks

Change-Id: I7cd727657a9e426a43f72d1c5b843e581cfe8c5d
Reviewed-on: https://gerrit.libreoffice.org/11608
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>