Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors detected by fdscan to improve user-perceived crash rate #886

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class GoTun2SocksProvider(
private const val VPN_MTU = 1500
}

private var mInterface: ParcelFileDescriptor? = null

@Synchronized
private fun createBuilder(
vpnService: VpnService,
Expand Down Expand Up @@ -87,9 +85,7 @@ class GoTun2SocksProvider(
builder.setSession(sessionName)

// Create a new mInterface using the builder and save the parameters.
mInterface = builder.establish()
Logger.d(TAG, "New mInterface: " + mInterface)
return mInterface
return builder.establish()
}

override fun run(
Expand All @@ -103,11 +99,12 @@ class GoTun2SocksProvider(
val defaultLocale = Locale.getDefault()
try {
Logger.debug(TAG, "Creating VpnBuilder before starting tun2socks")
val intf: ParcelFileDescriptor? = createBuilder(vpnService, builder)
Logger.debug(TAG, "Running tun2socks")
if (intf != null) {
val intf = createBuilder(vpnService, builder)
val tunFd = intf?.detachFd()
if (tunFd != null) {
Logger.debug(TAG, "Running tun2socks")
Internalsdk.tun2Socks(
intf.getFd().toLong(),
tunFd.toLong(),
socksAddr,
dnsGrabAddr,
VPN_MTU.toLong(),
Expand All @@ -126,10 +123,5 @@ class GoTun2SocksProvider(
override fun stop() {
Logger.d(TAG, "stop")
Internalsdk.stopTun2Socks()
mInterface?.let {
Logger.d(TAG, "closing interface")
mInterface!!.close()
mInterface = null
}
}
}