summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2017-04-11 21:43:56 +0200
committerAndré Hartmann <aha_1980@gmx.de>2017-04-25 08:59:08 +0000
commitf9cd9f7da643274e0c39fd62b8b12a6a83fc203d (patch)
tree9bbb578951045371031a3295551f0fb211570aee
parent52cc18ff1977217c38f9d426ecdded68b0646897 (diff)
VectorCAN: Fix crash when device open failsv5.9.0-beta4
xlOpenPort() fails to open "can0" when the Vector vxlapi.dll is available, but no Vector device driver is installed. Calling xlClosePort() afterwards crashes. Before this patch, xlDeactivateChannel() and xlClosePort() were called unconditionally as part of VectorCanBackendPrivate::close() when any VectorCanBackendPrivate::open() step failed. Now xlClosePort() is only called when xlOpenPort() succeeded. Also guard xlDeactivateChannel() for consistence (doesn't make sense to call it on a closed device), even if this never crashed for me. Change-Id: Iad480f7e02ca8f45b8cc4d1d8930640b2d8cbeb2 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/plugins/canbus/vectorcan/vectorcanbackend.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/plugins/canbus/vectorcan/vectorcanbackend.cpp b/src/plugins/canbus/vectorcan/vectorcanbackend.cpp
index 289eaea..6c455da 100644
--- a/src/plugins/canbus/vectorcan/vectorcanbackend.cpp
+++ b/src/plugins/canbus/vectorcan/vectorcanbackend.cpp
@@ -171,6 +171,7 @@ bool VectorCanBackendPrivate::open()
if (Q_UNLIKELY(status != XL_SUCCESS || portHandle == XL_INVALID_PORTHANDLE)) {
q->setError(systemErrorString(status), QCanBusDevice::ConnectionError);
+ portHandle = XL_INVALID_PORTHANDLE;
return false;
}
}
@@ -211,6 +212,11 @@ void VectorCanBackendPrivate::close()
delete writeNotifier;
writeNotifier = nullptr;
+ // xlClosePort can crash on systems with vxlapi.dll but no device driver installed.
+ // Therefore avoid calling any close function when the portHandle is invalid anyway.
+ if (portHandle == XL_INVALID_PORTHANDLE)
+ return;
+
{
const XLstatus status = ::xlDeactivateChannel(portHandle, channelMask);
if (Q_UNLIKELY(status != XL_SUCCESS)) {