Skip to content

Commit 23ca244

Browse files
jigar-fclaude
andcommitted
Address PR review: free FFI result pointers + widen VPN guard
- Free the C string returned by clearTunnelCache/runURLTests/sendConfigRequest in a finally block; toDartString() only converts, so these were leaking the C.CString("ok") allocation on every call. - Gate refresh-configuration on `!= VPNStatus.disconnected` so connecting, disconnecting, missingPermission and error states are also blocked, since clearing the tunnel cache requires the tunnel to be fully stopped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e93da84 commit 23ca244

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

lib/features/support/support.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ class Support extends ConsumerWidget {
163163
BuildContext context,
164164
WidgetRef ref,
165165
) async {
166+
// Clearing the tunnel cache requires the tunnel to be fully stopped, so
167+
// only proceed when the VPN is disconnected. Any other state (connected,
168+
// connecting, disconnecting, missingPermission, error) is treated as an
169+
// active/in-transition tunnel and is blocked.
166170
final vpnStatus = ref.read(vpnProvider);
167-
if (vpnStatus == VPNStatus.connected) {
171+
if (vpnStatus != VPNStatus.disconnected) {
168172
AppDialog.dialog(
169173
context: context,
170174
title: 'turn_off_vpn'.i18n,

lib/lantern/lantern_ffi_service.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,12 @@ class LanternFFIService implements LanternCoreService {
17991799
Future<Either<Failure, Unit>> runURLTests() async {
18001800
try {
18011801
final result = await runInBackground<String>(() async {
1802-
return _ffiService.runURLTests().toDartString();
1802+
final resultPtr = _ffiService.runURLTests();
1803+
try {
1804+
return resultPtr.toDartString();
1805+
} finally {
1806+
_ffiService.freeCString(resultPtr);
1807+
}
18031808
});
18041809
checkAPIError(result);
18051810
return right(unit);
@@ -1813,7 +1818,12 @@ class LanternFFIService implements LanternCoreService {
18131818
Future<Either<Failure, Unit>> sendConfigRequest() async {
18141819
try {
18151820
final result = await runInBackground<String>(() async {
1816-
return _ffiService.updateConfig().toDartString();
1821+
final resultPtr = _ffiService.updateConfig();
1822+
try {
1823+
return resultPtr.toDartString();
1824+
} finally {
1825+
_ffiService.freeCString(resultPtr);
1826+
}
18171827
});
18181828
checkAPIError(result);
18191829
return right(unit);
@@ -1827,7 +1837,12 @@ class LanternFFIService implements LanternCoreService {
18271837
Future<Either<Failure, Unit>> clearTunnelCache() async {
18281838
try {
18291839
final result = await runInBackground<String>(() async {
1830-
return _ffiService.clearTunnelCache().toDartString();
1840+
final resultPtr = _ffiService.clearTunnelCache();
1841+
try {
1842+
return resultPtr.toDartString();
1843+
} finally {
1844+
_ffiService.freeCString(resultPtr);
1845+
}
18311846
});
18321847
checkAPIError(result);
18331848
return right(unit);

0 commit comments

Comments
 (0)