So this fixes that problem, and also I slightly changed the code to give the same result in fewer lines --
 986    list = sess_list;
 987    while (list)
 988    {
 989       sess = list->data;
 990       if ((sess->server == serv))
 991          userlist_set_away (sess, nick, reason? TRUE: FALSE);
 992       list = list->next;
 993    }