After searching for a while I found the answer in this page: Logout codeigniter .
My original code was:
$this->session->sess_destroy();
redirect(base_url().'posts');
$this->session->unset_userdata('userID');
$this->session->unset_userdata('user_type');
$this->session->sess_destroy();
redirect(base_url().'posts');
The explanation is in the link provided.
This are my first steps with this framework and I really like it.
That's all!!