Permalink
Browse files

MB-12451 mcd leak when socket closes during read

Move the code which requires engine release to be
before the place we tear down the engine reference.

Change-Id: I14a9312ab6673f6f44e2f3561519090ba8708276
Reviewed-on: http://review.couchbase.org/42525
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Patrick Varley <patrick@couchbase.com>
  • Loading branch information...
1 parent 349f670 commit b812600d53048d39bd45ef500900b06455e37047 @jimwwalker jimwwalker committed with mcpaddy Oct 31, 2014
Showing with 9 additions and 4 deletions.
  1. +9 −4 daemon/memcached.c
View
@@ -910,10 +910,8 @@ conn *conn_new(const SOCKET sfd, const int parent_port,
return c;
}
-static void conn_cleanup(conn *c) {
- assert(c != NULL);
-
- if (c->item) {
+static void conn_cleanup_engine_allocations(conn* c) {
+ if (c->item) {
settings.engine.v1->release(settings.engine.v0, c, c->item);
c->item = 0;
}
@@ -923,6 +921,10 @@ static void conn_cleanup(conn *c) {
settings.engine.v1->release(settings.engine.v0, c, *(c->icurr));
}
}
+}
+
+static void conn_cleanup(conn *c) {
+ assert(c != NULL);
if (c->suffixleft != 0) {
for (; c->suffixleft > 0; c->suffixleft--, c->suffixcurr++) {
@@ -5936,6 +5938,9 @@ bool conn_closing(conn *c) {
safe_close(c->sfd);
c->sfd = INVALID_SOCKET;
+ /* engine::release any allocated state */
+ conn_cleanup_engine_allocations(c);
+
if (c->refcount > 1 || c->ewouldblock) {
conn_set_state(c, conn_pending_close);
} else {

0 comments on commit b812600

Please sign in to comment.