Jelajahi Sumber

Fix crash on uninitialized taps.

Adam Ierymenko 11 tahun lalu
induk
melakukan
d0b506c12b
1 mengubah file dengan 9 tambahan dan 2 penghapusan
  1. 9 2
      node/Network.cpp

+ 9 - 2
node/Network.cpp

@@ -60,8 +60,11 @@ Network::~Network()
 {
 	Thread::join(_setupThread);
 
-	std::string devPersistentId(_tap->persistentId());
-	delete _tap;
+	std::string devPersistentId;
+	if (_tap) {
+		devPersistentId = _tap->persistentId();
+		delete _tap;
+	}
 
 	if (_destroyOnDelete) {
 		Utils::rm(std::string(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + idString() + ".conf"));
@@ -296,9 +299,13 @@ void Network::threadMain()
 			_nc->putLocalConfig(lcentry,dn);
 #endif
 	} catch (std::exception &exc) {
+		delete _tap;
+		_tap = (EthernetTap *)0;
 		LOG("network %.16llx failed to initialize: %s",_id,exc.what());
 		_netconfFailure = NETCONF_FAILURE_INIT_FAILED;
 	} catch ( ... ) {
+		delete _tap;
+		_tap = (EthernetTap *)0;
 		LOG("network %.16llx failed to initialize: unknown error",_id);
 		_netconfFailure = NETCONF_FAILURE_INIT_FAILED;
 	}