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 Change-Id: Ib87d89a2e5fdb64b8f3dfae48d82c970f3ae6161
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user