Commits

Anonymous committed 15bd71f

vold: fix potential socket leak

Change-Id: Icdb4500fc1e055b058974087e1e518c878dc6b22
Signed-off-by: Kaspter Ju <kaspter@gmail.com>

Comments (0)

Files changed (1)

NetlinkManager.cpp

 
     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;
     close(mSock);
     mSock = -1;
 
-    return 0;
+    return status;
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.