summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Remi NGUYEN VAN <reminv@google.com> 2019-06-25 01:33:52 -0700
committer Remi NGUYEN VAN <reminv@google.com> 2019-06-25 09:08:14 +0000
commitc0fd05cf73b036aed874d83f0515adef7943bd4b (patch)
treedd6e61747712a0d534ed302fd759ff02775f4d2c
parentd701e951e0cfa7127ada4f0e402efee88c9ab24b (diff)
Fix leak of DhcpServer on tethering stop error
Tactical, minimal fix to make sure the DhcpServer is stopped when disabling tethering. The current code may throw if the interface is gone when calling mNMService.setInterfaceConfig() on teardown. Make sure DHCP is stopped regardless of what happens. A longer term fix will be to figure out the right flow to teardown the interface and avoid errors on setInterfaceConfig(). Bug: 124520692 Test: Manual: no more socket leaked when stopping USB tethering Merged-In: Ie73481e8d91ce43e4939f8c31a9ce431e382c6d9 (cherry picked from commit fe1ad3d0b86e1315906e18e33b65df2481eea63d) Change-Id: Ia80761cb42dc62b14128fc60009be82ae9a008da
-rw-r--r--services/net/java/android/net/ip/IpServer.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/services/net/java/android/net/ip/IpServer.java b/services/net/java/android/net/ip/IpServer.java
index 66884c60b0bc..6a6a1307723e 100644
--- a/services/net/java/android/net/ip/IpServer.java
+++ b/services/net/java/android/net/ip/IpServer.java
@@ -433,6 +433,9 @@ public class IpServer extends StateMachine {
}
}
ifcg.clearFlag("running");
+
+ // TODO: this may throw if the interface is already gone. Do proper handling and
+ // simplify the DHCP server start/stop.
mNMService.setInterfaceConfig(mIfaceName, ifcg);
if (!configureDhcp(enabled, (Inet4Address) addr, prefixLen)) {
@@ -440,6 +443,14 @@ public class IpServer extends StateMachine {
}
} catch (Exception e) {
mLog.e("Error configuring interface " + e);
+ if (!enabled) {
+ try {
+ // Calling stopDhcp several times is fine
+ stopDhcp();
+ } catch (Exception dhcpError) {
+ mLog.e("Error stopping DHCP", dhcpError);
+ }
+ }
return false;
}