Make get_allocated_nodes always set get_allocated_nodes_retval as retval

The old code was broken because the name of the variable passed to
get_allocated_nodes to save the result should not be used inside the
function; but it was...

Also, use local variables.