From 48b6a237d21a3a634694d823a1acdb0c6302474e Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Mon, 29 Mar 2010 10:11:16 -0400 Subject: fix MessagingPort leaking SERVER-777 From: Guillaume Delannoy Signed-off-by: Eliot Horowitz --- db/db.cpp | 24 ++++++++++++------------ util/message_server_port.cpp | 5 ++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/db/db.cpp b/db/db.cpp index 51369bbb5e9..9be403129a3 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -193,22 +193,22 @@ namespace mongo { LastError *le = new LastError(); lastError.reset(le); - MessagingPort& dbMsgPort = *connGrab; + auto_ptr dbMsgPort( connGrab ); connGrab = 0; Client& c = cc(); try { - c.getAuthenticationInfo()->isLocalHost = dbMsgPort.farEnd.isLocalHost(); + c.getAuthenticationInfo()->isLocalHost = dbMsgPort->farEnd.isLocalHost(); Message m; while ( 1 ) { m.reset(); - if ( !dbMsgPort.recv(m) ) { + if ( !dbMsgPort->recv(m) ) { if( !cmdLine.quiet ) - log() << "end connection " << dbMsgPort.farEnd.toString() << endl; - dbMsgPort.shutdown(); + log() << "end connection " << dbMsgPort->farEnd.toString() << endl; + dbMsgPort->shutdown(); break; } @@ -220,11 +220,11 @@ namespace mongo { lastError.startRequest( m , le ); DbResponse dbresponse; - if ( !assembleResponse( m, dbresponse, dbMsgPort.farEnd.sa ) ) { - out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl; + if ( !assembleResponse( m, dbresponse, dbMsgPort->farEnd.sa ) ) { + out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort->farEnd.toString() << endl; /* todo: we may not wish to allow this, even on localhost: very low priv accounts could stop us. */ - if ( dbMsgPort.farEnd.isLocalHost() ) { - dbMsgPort.shutdown(); + if ( dbMsgPort->farEnd.isLocalHost() ) { + dbMsgPort->shutdown(); sleepmillis(50); problem() << "exiting end msg" << endl; dbexit(EXIT_CLEAN); @@ -235,17 +235,17 @@ namespace mongo { } if ( dbresponse.response ) - dbMsgPort.reply(m, *dbresponse.response, dbresponse.responseTo); + dbMsgPort->reply(m, *dbresponse.response, dbresponse.responseTo); } } catch ( AssertionException& ) { problem() << "AssertionException in connThread, closing client connection" << endl; - dbMsgPort.shutdown(); + dbMsgPort->shutdown(); } catch ( SocketException& ) { problem() << "SocketException in connThread, closing client connection" << endl; - dbMsgPort.shutdown(); + dbMsgPort->shutdown(); } catch ( const ClockSkewException & ) { exitCleanly( EXIT_CLOCK_SKEW ); diff --git a/util/message_server_port.cpp b/util/message_server_port.cpp index fa8f9e5e8d5..2350ec2d665 100644 --- a/util/message_server_port.cpp +++ b/util/message_server_port.cpp @@ -31,7 +31,7 @@ namespace mongo { void threadRun(){ assert( grab ); - MessagingPort * p = grab; + auto_ptr p( grab ); grab = 0; Message m; @@ -45,12 +45,11 @@ namespace mongo { break; } - handler->process( m , p ); + handler->process( m , p.get() ); } } catch ( ... ){ problem() << "uncaught exception in PortMessageServer::threadRun, closing connection" << endl; - delete p; } } -- cgit v1.2.1