fixes pgsql double free of threadstorage