]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
rsocket: Fix removing rsocket from service thread
authorSean Hefty <sean.hefty@intel.com>
Thu, 3 Jul 2014 20:55:39 +0000 (13:55 -0700)
committerSean Hefty <sean.hefty@intel.com>
Thu, 3 Jul 2014 20:55:39 +0000 (13:55 -0700)
When removing an rsocket from a service thread, we replace
the removed service with the one at the end of the service list.
This keeps the array tightly packed.  However, rs_svc_rm_rs
decrements the rsocket count before doing the swap.  The result
is that the entry at the end of the list gets dropped off.
Defer decrementing the count until the swap has been made.

In this case, the cnt value is a valid index into the array,
because we start at index 1.  Index 0 is used internally by
the service thread.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
src/rsocket.c

index f81fb1b8479614db7387ee4d81b08f18be7f250f..e9d12c7520cb08a599945bdad8ada63702186942 100644 (file)
@@ -3947,11 +3947,11 @@ static int rs_svc_rm_rs(struct rs_svc *svc, struct rsocket *rs)
 
        for (i = 1; i <= svc->cnt; i++) {
                if (svc->rss[i] == rs) {
-                       svc->cnt--;
                        svc->rss[i] = svc->rss[svc->cnt];
                        memcpy(svc->contexts + i * svc->context_size,
                               svc->contexts + svc->cnt * svc->context_size,
                               svc->context_size);
+                       svc->cnt--;
                        return 0;
                }
        }