Просмотр исходного кода

Allow repeated calls to psiphon_tunnel_start

mirokuratczyk 7 лет назад
Родитель
Сommit
89bd00b6cb
1 измененных файлов с 5 добавлено и 3 удалено
  1. 5 3
      ClientLibrary/PsiphonTunnel.go

+ 5 - 3
ClientLibrary/PsiphonTunnel.go

@@ -117,6 +117,11 @@ var managedStartResult *C.char
 // the optional `EstablishTunnelTimeoutSeconds` config field.
 func psiphon_tunnel_start(cConfigJSON, cEmbeddedServerEntryList, cClientPlatform, cNetworkID *C.char, timeout *uint64) *C.char {
 
+	// Stop any active tunnels
+	psiphon_tunnel_stop()
+
+	// NOTE: all arguments which are still referenced once Start returns should be copied onto the Go heap
+	//       to ensure that they don't disappear later on and cause Go to crash.
 	configJSON := C.GoString(cConfigJSON)
 	embeddedServerEntryList := C.GoString(cEmbeddedServerEntryList)
 	clientPlatform := C.GoString(cClientPlatform)
@@ -276,9 +281,6 @@ func psiphon_tunnel_start(cConfigJSON, cEmbeddedServerEntryList, cClientPlatform
 		tunnel.stopController()
 	}
 
-	// Free previous result
-	freeManagedStartResult()
-
 	// Return result
 	managedStartResult = marshalStartResult(result)