vold: fix potential socket leak

Change-Id: Icdb4500fc1e055b058974087e1e518c878dc6b22
Signed-off-by: Kaspter Ju <kaspter@gmail.com>
diff --git a/NetlinkManager.cpp b/NetlinkManager.cpp
index 2e15d7f..dbba303 100644
--- a/NetlinkManager.cpp
+++ b/NetlinkManager.cpp
@@ -65,31 +65,38 @@
 
     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 @@
     close(mSock);
     mSock = -1;
 
-    return 0;
+    return status;
 }