Skip to content

Commit

Permalink
CCBC-1488: Fixed incorrect refcounting in Connstart.
Browse files Browse the repository at this point in the history
Change-Id: I48d747b5216f3c1328dbb02a0918c18cb89c7e2c
Reviewed-on: http://review.couchbase.org/c/libcouchbase/+/161414
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information
brett19 committed Sep 13, 2021
1 parent 7a859c2 commit 8d0abcf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lcbio/connect.cc
Expand Up @@ -65,7 +65,7 @@ struct Connstart : ConnectionRequest {
void cancel() override;
void C_connect();

enum State { CS_PENDING, CS_CANCELLED, CS_CONNECTED, CS_ERROR };
enum State { CS_PENDING, CS_CANCELLED, CS_CONNECTED, CS_ERROR, CS_ERROR_CANCELLED };

void state_signal(State next_state, lcb_STATUS err);
void notify_success();
Expand Down Expand Up @@ -145,6 +145,12 @@ void Connstart::handler()
sock->refcount--; /* dereference because of unsuccessful attempt */
}
goto GT_DTOR;
} else if (state == CS_ERROR_CANCELLED) {
/* same as above, except the refcount has already been decremented */
if (sock != nullptr && sock->io->is_C() && sock->u.sd) {
sock->u.sd->lcbconn = nullptr;
}
goto GT_DTOR;
}

if (sock) {
Expand Down Expand Up @@ -225,7 +231,13 @@ void Connstart::cancel()
/* already inside user-defined handler */
return;
}
state = CS_CANCELLED;

if (state == CS_ERROR) {
state = CS_ERROR_CANCELLED;
} else {
state = CS_CANCELLED;
}

handler();
}

Expand Down

0 comments on commit 8d0abcf

Please sign in to comment.