From 31922cca3a063b2f413967312ae1f927d624a1ed Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Tue, 6 Jun 2017 10:47:05 +0200 Subject: 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 --- AudioManagerCore/src/CAmControlSender.cpp | 25 +++++++++++++---------- 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(mControlPluginFile,mlibHandle); - assert(destroyFunc!=NULL); - destroyFunc(mController); - if(mlibHandle) + close(mPipe[0]); + close(mPipe[1]); + + if (mlibHandle) { + void (*destroyFunc)(IAmControlSend*); + destroyFunc = getDestroyFunction(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 T* getCreateFunction(const std::string& libname, void*& librar template T* getDestroyFunction(const std::string& libname,void* libraryHandle) { logInfo("destroy : Trying to destroy : ",libname); + // cut off directories char* fileWithPath = const_cast(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) { -- cgit v1.2.1