Fixed segfaults, memory leaks and temporary clob cleanup