fixed pop function with a free() call