* [GAM-74] resolving issues found by coverity scan
authorchristian mueller <christian.ei.mueller@bmw.de>
Thu, 3 May 2012 12:40:20 +0000 (14:40 +0200)
committerchristian mueller <christian.ei.mueller@bmw.de>
Thu, 24 May 2012 11:40:22 +0000 (13:40 +0200)
Signed-off-by: christian mueller <christian.ei.mueller@bmw.de>
18 files changed:
AudioManagerDaemon/include/CAmDatabaseHandler.h
AudioManagerDaemon/include/CAmRoutingReceiver.h
AudioManagerDaemon/src/CAmCommandReceiver.cpp
AudioManagerDaemon/src/CAmCommandSender.cpp
AudioManagerDaemon/src/CAmControlReceiver.cpp
AudioManagerDaemon/src/CAmDatabaseHandler.cpp
AudioManagerDaemon/src/CAmDatabaseObserver.cpp
AudioManagerDaemon/src/CAmDbusWrapper.cpp
AudioManagerDaemon/src/CAmRoutingReceiver.cpp
AudioManagerDaemon/src/CAmRoutingSender.cpp
AudioManagerDaemon/src/CAmSocketHandler.cpp
AudioManagerDaemon/src/CAmTelnetServer.cpp
AudioManagerDaemon/src/main.cpp
AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp
PluginCommandInterfaceDbus/src/CAmDbusMessageHandler.cpp
PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.cpp
PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.cpp
PluginRoutingInterfaceDbus/src/CAmDbusMessageHandler.cpp

index 8509594..e8e44c2 100644 (file)
@@ -129,7 +129,7 @@ public:
     am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const;
     am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const;
     am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const;
-    am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e state) const;
+    am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const;
     am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree);
     am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID);
     am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID);
index e8558c1..ca2a4b4 100644 (file)
@@ -95,9 +95,9 @@ private:
     CAmSocketHandler *mpSocketHandler; //!< pointer to sockethandler
     CAmDbusWrapper *mpDBusWrapper; //!< pointer to dbuswrapper
 
-    uint16_t handleCount; //!< counts all handles
     std::vector<uint16_t> mListStartupHandles; //!< list of handles that wait for a confirm
     std::vector<uint16_t> mListRundownHandles; //!< list of handles that wait for a confirm
+    uint16_t handleCount; //!< counts all handles
     bool mWaitStartup; //!< if true confirmation will be sent if list of handles = 0
     bool mWaitRundown; //!< if true confirmation will be sent if list of handles = 0
 
index d656720..c507d5f 100644 (file)
@@ -33,7 +33,9 @@ namespace am
 CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) :
         mDatabaseHandler(iDatabaseHandler), //
         mControlSender(iControlSender), //
+        mDBusWrapper(NULL), //
         mSocketHandler(iSocketHandler), //
+        handleCount(0),//
         mListStartupHandles(), //
         mListRundownHandles(), //
         mWaitStartup(false), //
@@ -50,6 +52,7 @@ CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAm
         mControlSender(iControlSender), //
         mDBusWrapper(iDBusWrapper), //
         mSocketHandler(iSocketHandler), //
+        handleCount(0),//
         mListStartupHandles(), //
         mListRundownHandles(), //
         mWaitStartup(false), //
@@ -165,6 +168,7 @@ am_Error_e CAmCommandReceiver::getDBusConnectionWrapper(CAmDbusWrapper*& dbusCon
     dbusConnectionWrapper = mDBusWrapper;
     return (E_OK);
 #else
+    dbusConnectionWrapper = NULL;
     return (E_UNKNOWN);
 #endif /*WITH_DBUS_WRAPPER*/
 }
index 2199a42..b3609de 100644 (file)
@@ -107,6 +107,7 @@ CAmCommandSender::CAmCommandSender(const std::vector<std::string>& listOfPluginD
         if (!commander)
         {
             logInfo("CommandPlugin initialization failed. Entry Function not callable");
+            dlclose(tempLibHandle);
             continue;
         }
 
@@ -120,6 +121,7 @@ CAmCommandSender::CAmCommandSender(const std::vector<std::string>& listOfPluginD
         if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR)))
         {
             logInfo("CommandInterface initialization failed. Version of Interface to old");
+            dlclose(tempLibHandle);
             continue;
         }
 
index 23ae544..51a2225 100644 (file)
@@ -63,6 +63,7 @@ am_Error_e CAmControlReceiver::connect(am_Handle_s & handle, am_connectionID_t &
     tempConnection.sourceID = sourceID;
     tempConnection.connectionFormat = format;
     tempConnection.connectionID = 0;
+    tempConnection.delay=-1;
 
     //todo: enter function to find out what happends if the same connection is in the course of being build up.
     if (mDatabaseHandler->existConnection(tempConnection))
index 1f7e9f8..e4e0bff 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "CAmDatabaseHandler.h"
 #include <cassert>
+#include <stdexcept>
 #include <vector>
 #include <fstream>
 #include <sstream>
@@ -3844,7 +3845,7 @@ am_Error_e CAmDatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t s
     return (E_OK);
 }
 
-am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
+am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const
 {
     assert(domainID!=0);
     sqlite3_stmt* query = NULL;
index ae81a4e..0b8b481 100644 (file)
@@ -36,6 +36,7 @@ namespace am {
 CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) :
         mCommandSender(iCommandSender), //
         mRoutingSender(iRoutingSender), //
+        mTelnetServer(NULL), //
         mSerializer(iSocketHandler) //
 {
     assert(mCommandSender!=0);
index 592d58e..76290ee 100644 (file)
@@ -26,6 +26,7 @@
 #include <string>
 #include <cassert>
 #include <cstdlib>
+#include <stdexcept>
 #include "shared/CAmDltWrapper.h"
 #include "shared/CAmSocketHandler.h"
 
@@ -104,8 +105,8 @@ CAmDbusWrapper::CAmDbusWrapper(CAmSocketHandler* socketHandler, DBusBusType type
     }
     if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
     {
-        logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?", ret);
-        exit(1);
+        logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?");
+        throw std::runtime_error("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?");
     }
 }
 
@@ -260,9 +261,15 @@ void CAmDbusWrapper::removeWatchDelegate(DBusWatch *watch, void *userData)
     std::map<DBusWatch*, sh_pollHandle_t>::iterator iterator = mMapHandleWatch.begin();
     iterator = mMapHandleWatch.find(watch);
     if (iterator != mMapHandleWatch.end())
+    {
         mpSocketHandler->removeFDPoll(iterator->second);
-    logInfo("DBusWrapper::removeWatch removed watch with handle", iterator->second);
-    mMapHandleWatch.erase(iterator);
+        logInfo("DBusWrapper::removeWatch removed watch with handle", iterator->second);
+        mMapHandleWatch.erase(iterator);
+    }
+    else
+    {
+        logError("DBusWrapper::removeWatch could not find handle !");
+    }
 }
 
 void CAmDbusWrapper::toogleWatch(DBusWatch *watch, void *userData)
@@ -302,6 +309,8 @@ dbus_bool_t CAmDbusWrapper::addTimeout(DBusTimeout *timeout, void* userData)
 
 dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userData)
 {
+    (void)userData;
+
     if (!dbus_timeout_get_enabled(timeout))
         return (false);
 
index ea6bfeb..1fb0dac 100644 (file)
@@ -38,6 +38,7 @@ CAmRoutingReceiver::CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAm
         mpSocketHandler(iSocketHandler), //
         mListStartupHandles(), //
         mListRundownHandles(), //
+        handleCount(0), //
         mWaitStartup(false), //
         mWaitRundown(false)
 {
@@ -55,6 +56,7 @@ CAmRoutingReceiver::CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAm
         mpDBusWrapper(iDBusWrapper), //
         mListStartupHandles(), //
         mListRundownHandles(), //
+        handleCount(0), //
         mWaitStartup(false), //
         mWaitRundown(false)
 {
index b6279a7..050ff45 100644 (file)
@@ -113,6 +113,7 @@ CAmRoutingSender::CAmRoutingSender(const std::vector<std::string>& listOfPluginD
         if (!router)
         {
             logError("RoutingSender::RoutingSender RoutingPlugin initialization failed. Entry Function not callable");
+            dlclose(tempLibHandle);
             continue;
         }
 
@@ -128,6 +129,7 @@ CAmRoutingSender::CAmRoutingSender(const std::vector<std::string>& listOfPluginD
         if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR)))
         {
             logInfo("RoutingPlugin initialization failed. Version of Interface to old");
+            dlclose(tempLibHandle);
             continue;
         }
 
index 27cb4bb..9bef60e 100644 (file)
@@ -312,6 +312,8 @@ am_Error_e CAmSocketHandler::updateTimer(const sh_timerHandle_t handle, const ti
 
     //we add here the time difference between startTime and currenttime, because this time will be substracted later on in timecorrection
     timespec currentTime, timeoutsCorrected;
+    currentTime.tv_nsec=timeoutsCorrected.tv_nsec=0;
+    currentTime.tv_sec=timeoutsCorrected.tv_sec=0;
     clock_gettime(CLOCK_MONOTONIC, &currentTime);
     if (!gDispatchDone) //the mainloop is started
         timeoutsCorrected = timespecAdd(timeouts, timespecSub(currentTime, mStartTime));
index 3af05af..ed28f9c 100644 (file)
@@ -69,6 +69,7 @@ CAmTelnetServer::CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSen
 
     //setup the port Listener
     mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+    assert (mConnectFD>0);
     setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
     memset(&servAddr, 0, sizeof(servAddr));
     servAddr.sin_family = AF_INET;
@@ -107,6 +108,8 @@ void CAmTelnetServer::connectSocket(const pollfd pfd, const sh_pollHandle_t hand
     connection.handle = 0;
     connection.filedescriptor = accept(pfd.fd, (struct sockaddr*) &answer, &len);
 
+    assert(connection.filedescriptor>0);
+
     // Notiy menuhelper
     mTelnetMenuHelper.newSocketConnection(connection.filedescriptor);
 
@@ -167,6 +170,11 @@ bool CAmTelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData)
         if (iterator->handle == handle)
             break;
     }
+    if (iterator==mListConnections.end())
+    {
+        logError("CAmTelnetServer::dispatchData could not find handle !");
+        return (false);
+    }
 
     std::string command;
     std::queue<std::string> MsgQueue;
@@ -174,9 +182,12 @@ bool CAmTelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData)
     {
         sliceCommand(mListMessages.front(), command, MsgQueue);
         mListMessages.pop();
+        mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor);
+    }
+    else
+    {
+        logError("CAmTelnetServer::dispatchData Message queue was empty!");
     }
-
-    mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor);
 
     // must return false to stop endless polling
     return (false);
index b01b98d..ad908ec 100644 (file)
@@ -270,44 +270,8 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context)
     exit(1);
 }
 
-/**
- * main
- * @param argc
- * @param argv
- * @return
- */
-int main(int argc, char *argv[])
+void mainProgram()
 {
-    listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
-    listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
-
-    //parse the commandline options
-    parseCommandLine(argc, (char**) argv);
-
-    CAmDltWrapper::instance(enableNoDLTDebug)->registerApp("AudioManagerDeamon", "AudioManagerDeamon");
-    CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context");
-    logInfo("The Audiomanager is started");
-    logInfo("The version of the Audiomanager", DAEMONVERSION);
-
-    //now the signal handler:
-    struct sigaction signalAction;
-    memset(&signalAction, '\0', sizeof(signalAction));
-    signalAction.sa_sigaction = &signalHandler;
-    signalAction.sa_flags = SA_SIGINFO;
-    sigaction(SIGINT, &signalAction, NULL);
-    sigaction(SIGQUIT, &signalAction, NULL);
-    sigaction(SIGTERM, &signalAction, NULL);
-    sigaction(SIGHUP, &signalAction, NULL);
-    sigaction(SIGQUIT, &signalAction, NULL);
-
-    struct sigaction signalChildAction;
-    memset(&signalChildAction, '\0', sizeof(signalChildAction));
-    signalChildAction.sa_flags = SA_NOCLDWAIT;
-    sigaction(SIGCHLD, &signalChildAction, NULL);
-
-    //register new out of memory handler
-    std::set_new_handler(&OutOfMemoryHandler);
-
     //Instantiate all classes. Keep in same order !
     CAmSocketHandler iSocketHandler;
 
@@ -351,6 +315,60 @@ int main(int argc, char *argv[])
     //start the mainloop here....
     iSocketHandler.start_listenting();
 
+}
+
+/**
+ * main
+ * @param argc
+ * @param argv
+ * @return
+ */
+int main(int argc, char *argv[])
+{
+    listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
+    listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
+
+    //parse the commandline options
+    parseCommandLine(argc, (char**) argv);
+
+    CAmDltWrapper::instance(enableNoDLTDebug)->registerApp("AudioManagerDeamon", "AudioManagerDeamon");
+    CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context");
+    logInfo("The Audiomanager is started");
+    logInfo("The version of the Audiomanager", DAEMONVERSION);
+
+    //now the signal handler:
+    struct sigaction signalAction;
+    memset(&signalAction, '\0', sizeof(signalAction));
+    signalAction.sa_sigaction = &signalHandler;
+    signalAction.sa_flags = SA_SIGINFO;
+    sigaction(SIGINT, &signalAction, NULL);
+    sigaction(SIGQUIT, &signalAction, NULL);
+    sigaction(SIGTERM, &signalAction, NULL);
+    sigaction(SIGHUP, &signalAction, NULL);
+    sigaction(SIGQUIT, &signalAction, NULL);
+
+    struct sigaction signalChildAction;
+    memset(&signalChildAction, '\0', sizeof(signalChildAction));
+    signalChildAction.sa_flags = SA_NOCLDWAIT;
+    sigaction(SIGCHLD, &signalChildAction, NULL);
+
+    //register new out of memory handler
+    std::set_new_handler(&OutOfMemoryHandler);
+
+    try
+    {
+        //we do this to catch all exceptions and have a graceful ending just in case
+        mainProgram();
+    }
+
+    catch (std::exception& exc)
+    {
+        logError("The AudioManager ended by throwing the exception", exc.what());
+        //todo: ergency exit here... call destructors etc...
+        exit(EXIT_FAILURE);
+    }
+
+
     close(fd0);
     close(fd1);
     close(fd2);
index 079625a..a1b7e39 100644 (file)
@@ -330,7 +330,6 @@ TEST_F(CAmDatabaseHandlerTest,getSourceInfo)
         {
             equal = equal && pCF.compareSource(listIterator, secondDynamicSource);
         }
-        pCF.compareSource(listIterator, secondDynamicSource);
 
     }ASSERT_EQ(true, equal);
 
index f84a994..94a0421 100644 (file)
@@ -147,7 +147,7 @@ dbus_bool_t CAmDbusMessageHandler::getBool()
 
 char CAmDbusMessageHandler::getByte()
 {
-    char param;
+    char param(0);
 
     if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&mDBusMessageIter))
     {
@@ -165,7 +165,7 @@ char CAmDbusMessageHandler::getByte()
 
 dbus_uint16_t CAmDbusMessageHandler::getUInt()
 {
-    dbus_uint16_t param;
+    dbus_uint16_t param(0);
 
 #ifdef GLIB_DBUS_TYPES_TOLERANT
     if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
@@ -187,7 +187,7 @@ dbus_uint16_t CAmDbusMessageHandler::getUInt()
 
 dbus_int16_t CAmDbusMessageHandler::getInt()
 {
-    dbus_int16_t param;
+    dbus_int16_t param(0);
 
 #ifdef GLIB_DBUS_TYPES_TOLERANT
     if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
@@ -209,7 +209,7 @@ dbus_int16_t CAmDbusMessageHandler::getInt()
 
 double CAmDbusMessageHandler::getDouble()
 {
-    double param;
+    double param(0);
     if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&mDBusMessageIter))
     {
         log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getDouble DBUS handler argument is no double!");
index 0ef24bc..34ef0c9 100644 (file)
@@ -33,7 +33,8 @@
 using namespace am;
 using namespace testing;
 
-CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest()
+CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest() :
+        ppCommandSend(NULL) //
 {
     CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest");
     logInfo("dbusCommandInterfaceSignalTest started");
index 771a0d0..c12e3c1 100644 (file)
@@ -44,7 +44,8 @@ void* run_the_loop(void* wrapper)
     return (NULL);
 }
 
-CAmCommandSenderDbusTest::CAmCommandSenderDbusTest()
+CAmCommandSenderDbusTest::CAmCommandSenderDbusTest() :
+        ppCommandSend(NULL) //
 {
     CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest");
 }
index 65b77b6..e8c4826 100644 (file)
@@ -161,7 +161,7 @@ dbus_bool_t CAmRoutingDbusMessageHandler::getBool()
 
 char CAmRoutingDbusMessageHandler::getByte(DBusMessageIter& iter, bool next)
 {
-    char param;
+    char param(0);
 
     if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&iter))
     {
@@ -185,7 +185,7 @@ char CAmRoutingDbusMessageHandler::getByte()
 
 dbus_uint16_t CAmRoutingDbusMessageHandler::getUInt(DBusMessageIter& iter, bool next)
 {
-    dbus_uint16_t param;
+    dbus_uint16_t param(0);
 #ifdef GLIB_DBUS_TYPES_TOLERANT
     if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&iter) && DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&iter))
 #else
@@ -212,7 +212,7 @@ dbus_uint16_t CAmRoutingDbusMessageHandler::getUInt()
 
 dbus_int16_t CAmRoutingDbusMessageHandler::getInt(DBusMessageIter& iter, bool next)
 {
-    dbus_int16_t param;
+    dbus_int16_t param(0);
 #ifdef GLIB_DBUS_TYPES_TOLERANT
     if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&iter) && DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&iter))
 #else
@@ -239,7 +239,7 @@ dbus_int16_t CAmRoutingDbusMessageHandler::getInt()
 
 double CAmRoutingDbusMessageHandler::getDouble(DBusMessageIter& iter, bool next)
 {
-    double param;
+    double param(0);
     if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&iter))
     {
         log(&routingDbus, DLT_LOG_ERROR, "DBusMessageHandler::getDouble DBUS handler argument is no double!");