diff options
author | Jens Lorenz <jlorenz@de.adit-jv.com> | 2017-06-06 10:47:05 +0200 |
---|---|---|
committer | Jens Lorenz <jlorenz@de.adit-jv.com> | 2017-09-29 11:42:01 +0200 |
commit | 31922cca3a063b2f413967312ae1f927d624a1ed (patch) | |
tree | 1fd16a2e86ac87a70db85c1d7043483902e3f9ce | |
parent | 4bfe4632624bc3ee13fa85f0ffdc23d7618e65e3 (diff) | |
download | audiomanager-31922cca3a063b2f413967312ae1f927d624a1ed.tar.gz |
AMUtil: Fix for destroy controller on rundown
On rundown the controller will be unloaded.
In case the controller wasn't loaded successfully or
the controller doesn't implement the destroy function
the rundown of AudioManager crashed.
Signed-off-by: Jens Lorenz <jlorenz@de.adit-jv.com>
-rw-r--r-- | AudioManagerCore/src/CAmControlSender.cpp | 25 | ||||
-rw-r--r-- | AudioManagerUtilities/include/TAmPluginTemplate.h | 6 |
2 files changed, 20 insertions, 11 deletions
diff --git a/AudioManagerCore/src/CAmControlSender.cpp b/AudioManagerCore/src/CAmControlSender.cpp index ce5d132..17a9b2b 100644 --- a/AudioManagerCore/src/CAmControlSender.cpp +++ b/AudioManagerCore/src/CAmControlSender.cpp @@ -153,20 +153,23 @@ CAmControlSender::CAmControlSender(std::string controlPluginFile,CAmSocketHandle CAmControlSender::~CAmControlSender() { - close(mPipe[0]); - close(mPipe[1]); - void (*destroyFunc)(IAmControlSend*); - destroyFunc = getDestroyFunction<void(IAmControlSend*)>(mControlPluginFile,mlibHandle); - assert(destroyFunc!=NULL); - destroyFunc(mController); - if(mlibHandle) + close(mPipe[0]); + close(mPipe[1]); + + if (mlibHandle) { + void (*destroyFunc)(IAmControlSend*); + destroyFunc = getDestroyFunction<void(IAmControlSend*)>(mControlPluginFile, mlibHandle); + if (destroyFunc) + { + destroyFunc(mController); + } + else + { + logError("CAmControlSender Dtor: destroyFunc is invalid or not found"); + } dlclose(mlibHandle); } - else - { - logError("CAmControlSender Dtor: mlibHandle is invalid"); - } } am_Error_e CAmControlSender::hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) diff --git a/AudioManagerUtilities/include/TAmPluginTemplate.h b/AudioManagerUtilities/include/TAmPluginTemplate.h index 8034497..95523f1 100644 --- a/AudioManagerUtilities/include/TAmPluginTemplate.h +++ b/AudioManagerUtilities/include/TAmPluginTemplate.h @@ -94,19 +94,25 @@ template<class T> T* getCreateFunction(const std::string& libname, void*& librar template<class T> T* getDestroyFunction(const std::string& libname,void* libraryHandle) { logInfo("destroy : Trying to destroy : ",libname); + // cut off directories char* fileWithPath = const_cast<char*>(libname.c_str()); std::string libFileName = basename(fileWithPath); + // cut off "lib" in front and cut off .so end" std::string destroyFunctionName = "destroy" + libFileName.substr(3, libFileName.length() - 6); + + // get entry point from shared lib dlerror(); // Clear any existing error union { void* voidPointer; T* typedPointer; } functionPointer; + functionPointer.voidPointer = dlsym(libraryHandle, destroyFunctionName.c_str()); T* destroyFunction = functionPointer.typedPointer; + const char* dlsym_error = dlerror(); if (!destroyFunction || dlsym_error) { |