This is causing regression tests to fail most of the time at step 12 of bug-879490.t and is also readily reproducible in isolation. The problem is that we're adding the new peer to our peer list *after* calling glusterd_friend_rpc_create. Unfortunately, by that time the disconnect-notify callback associated with our new RPC object might already have been invoked, removing *and freeing* the new peer. Thus, we add it after freeing it, leading to a corrupt list and a likely future crash - most often in glusterd_op_ac_send_lock while deleting the volume. The test fails because glusterd disconnects and dies in mid-operation. The fix is to change the order of addition to and deletion from the peer list. In the process, the general control flow of glusterd_friend_add was simplified so that it's not only correct but more readily verified to be so.
http://review.gluster.org/#change,4372
CHANGE: http://review.gluster.org/4372 (glusterd: fix memory corruption when probe fails) merged in master by Vijay Bellur (vbellur)
*** Bug 889382 has been marked as a duplicate of this bug. ***