From 15bd71f82fbb48c4e99eb54dd7d465df121c3f2c Mon Sep 17 00:00:00 2001 From: Kaspter Ju Date: Sat, 14 Apr 2012 10:48:45 +0800 Subject: [PATCH] vold: fix potential socket leak Change-Id: Icdb4500fc1e055b058974087e1e518c878dc6b22 Signed-off-by: Kaspter Ju --- NetlinkManager.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/NetlinkManager.cpp b/NetlinkManager.cpp index 2e15d7f..dbba303 100644 --- a/NetlinkManager.cpp +++ b/NetlinkManager.cpp @@ -65,31 +65,38 @@ int NetlinkManager::start() { if (setsockopt(mSock, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0) { SLOGE("Unable to set uevent socket SO_RCVBUFFORCE option: %s", strerror(errno)); - return -1; + goto out; } if (setsockopt(mSock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) { SLOGE("Unable to set uevent socket SO_PASSCRED option: %s", strerror(errno)); - return -1; + goto out; } if (bind(mSock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) { SLOGE("Unable to bind uevent socket: %s", strerror(errno)); - return -1; + goto out; } mHandler = new NetlinkHandler(mSock); if (mHandler->start()) { SLOGE("Unable to start NetlinkHandler: %s", strerror(errno)); - return -1; + goto out; } + return 0; + +out: + close(mSock); + return -1; } int NetlinkManager::stop() { + int status = 0; + if (mHandler->stop()) { SLOGE("Unable to stop NetlinkHandler: %s", strerror(errno)); - return -1; + status = -1; } delete mHandler; mHandler = NULL; @@ -97,5 +104,5 @@ int NetlinkManager::stop() { close(mSock); mSock = -1; - return 0; + return status; }