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

Fix crash when Start called more than once

mirokuratczyk 7 лет назад
Родитель
Сommit
94dfa81988
2 измененных файлов с 10 добавлено и 6 удалено
  1. 1 0
      ClientLibrary/PsiphonTunnel.go
  2. 9 6
      ClientLibrary/example/main.c

+ 1 - 0
ClientLibrary/PsiphonTunnel.go

@@ -321,6 +321,7 @@ func freeManagedStartResult() {
 		if managedMemory != nil {
 			C.free(managedMemory)
 		}
+		managedStartResult = nil
 	}
 }
 

+ 9 - 6
ClientLibrary/example/main.c

@@ -64,13 +64,16 @@ int main(int argc, char *argv[]) {
     // set timout
     long long timeout = 60;
 
-    // start will return once Psiphon connects or does not connect for timeout seconds
-    char *result = Start(psiphon_config, serverList, client_platform, network_id, timeout);
+    // Connect 5 times
+    for (int i = 0; i < 5; i++) {
+        // start will return once Psiphon connects or does not connect for timeout seconds
+        char *result = Start(psiphon_config, serverList, client_platform, network_id, timeout);
 
-    // print results
-    printf("Result: %s\n", result);
+        // print results
+        printf("Result: %s\n", result);
 
-    // The underlying memory of `result` is managed by PsiphonTunnel and is freed in Stop
-    Stop();
+        // The underlying memory of `result` is managed by PsiphonTunnel and is freed in Stop
+        Stop();
+    }
 }