better memory allocation for local variables
fix doble free error when there were no results