From 4bcfa9fabf7f888604a91de4c488422225f60989 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Mon, 26 Nov 2012 17:55:13 -0800 Subject: [PATCH] fixed potential Obd2Amb bug --- plugins/obd2plugin/obd2source.cpp | 5 +++++ plugins/obd2plugin/obd2source.h | 13 ++++++++++++- plugins/obd2plugin/obdpid.h | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index 9fd7631..ddd439c 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -727,6 +727,11 @@ void OBD2Source::subscribeToPropertyChanges(VehicleProperty::Property property) ObdPid *pid = obd2AmbInstance->createPidforProperty(property); + + if(!pid) + { + return; + } //If the pid is currently in the blacklist map, erase it. This allows for applications //to "un-blacklist" a pid by re-subscribing to it. diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h index 0182edc..60045de 100644 --- a/plugins/obd2plugin/obd2source.h +++ b/plugins/obd2plugin/obd2source.h @@ -79,6 +79,15 @@ public: supportedPidsList.push_back(new EngineCoolantPid()); supportedPidsList.push_back(new AirIntakeTemperaturePid()); } + + ~Obd2Amb() + { + for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++) + { + delete *itr; + } + } + ObdPid* createPidFromReply(ByteArray replyVector) { for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++) @@ -98,12 +107,14 @@ public: { for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++) { - if((*itr)->property == property) + VehicleProperty::Property p = (*itr)->property; + if(p == property) { ObdPid* obj = *itr; return obj->create(); } } + return NULL; } std::list supportedPidsList; diff --git a/plugins/obd2plugin/obdpid.h b/plugins/obd2plugin/obdpid.h index 3823317..a8b3965 100644 --- a/plugins/obd2plugin/obdpid.h +++ b/plugins/obd2plugin/obdpid.h @@ -129,7 +129,7 @@ public: bool tryParse(ByteArray replyVector) { ByteArray tmp = compress(cleanup(replyVector)); - if (tmp[1] != 0x05) + if (tmp[1] != id) { return false; } -- 2.7.4