Permalink
Browse files

CCBC-180 Do not destroy event struct in release_socket()

Segmentation fault when the hostname resolved into several addresses
and first of them reject couchbase connections. In this case
libcouchbase releases socket and destroys the the event structure, so
that subsequent calls will try to dereference NULL-event.

Change-Id: I963691e36e21d9e8c322f9dc9e5c9ec36e02ba37
Reviewed-on: http://review.couchbase.org/24620
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
1 parent 4053418 commit aadb912dc8d69bcf67805ada5dc196b3aef86375 @avsej avsej committed Feb 15, 2013
Showing with 11 additions and 3 deletions.
  1. +4 −0 RELEASE_NOTES.markdown
  2. +7 −3 src/instance.c
@@ -7,6 +7,10 @@ bugfixes. Do not forget to update this doc in every important patch.
* [minor] CCBC-175 Work properly on systems where EWOULDBLOCK != EAGAIN
+* [critical] CCBC-180 Segmentation fault when the hostname resolved
+ into several addresses and first of them reject couchbase
+ connections.
+
## 2.0.3 (2013-02-06)
* [minor] bypass SASL LIST MECH
View
@@ -308,9 +308,9 @@ lcb_error_t lcb_create(lcb_t *instance,
static void release_socket(lcb_t instance)
{
if (instance->sock != INVALID_SOCKET) {
- instance->io->v.v0.delete_event(instance->io, instance->sock, instance->event);
- instance->io->v.v0.destroy_event(instance->io, instance->event);
- instance->event = NULL;
+ if (instance->event) {
+ instance->io->v.v0.delete_event(instance->io, instance->sock, instance->event);
+ }
instance->io->v.v0.close(instance->io, instance->sock);
instance->sock = INVALID_SOCKET;
}
@@ -330,6 +330,10 @@ void lcb_destroy(lcb_t instance)
}
hashset_destroy(instance->timers);
release_socket(instance);
+ if (instance->event) {
+ instance->io->v.v0.destroy_event(instance->io, instance->event);
+ instance->event = NULL;
+ }
if (instance->timeout.event != NULL) {
instance->io->v.v0.delete_timer(instance->io, instance->timeout.event);

0 comments on commit aadb912

Please sign in to comment.