diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-01-07 21:04:04 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-01-08 09:10:42 +0000 |
commit | 900a2996c47a6fd32abf324db17bf1526894da36 (patch) | |
tree | 0e7b55cf93153e6d3d9b6d62051391a90efc1bae /cppu | |
parent | 45ec1d9b56cec41596f806ebf845ebfcd30c9f46 (diff) |
coverity#1261762 Resource leak
still leaks the handle of course, but c++izes the code and hides
the leak from coverity as a side-effect
Change-Id: Ieaab1545a98da1d699df93d020f0cb452ddf2516
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/uno/lbenv.cxx | 13 | ||||
-rw-r--r-- | cppu/source/uno/lbmap.cxx | 33 | ||||
-rw-r--r-- | cppu/source/uno/loadmodule.cxx | 6 | ||||
-rw-r--r-- | cppu/source/uno/loadmodule.hxx | 7 |
4 files changed, 29 insertions, 30 deletions
diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx index e8fa57d3bfea..721005d6a5ed 100644 --- a/cppu/source/uno/lbenv.cxx +++ b/cppu/source/uno/lbenv.cxx @@ -1055,20 +1055,19 @@ static bool loadEnv(OUString const & cLibStem, #else // late init with some code from matching uno language binding // will be unloaded by environment - oslModule hMod = cppu::detail::loadModule( cLibStem ); + osl::Module aMod; + bool bMod = cppu::detail::loadModule(aMod, cLibStem); - if (!hMod) + if (!bMod) return false; OUString aSymbolName(UNO_INIT_ENVIRONMENT); - uno_initEnvironmentFunc fpInit = (uno_initEnvironmentFunc) - ::osl_getFunctionSymbol( hMod, aSymbolName.pData ); + uno_initEnvironmentFunc fpInit = (uno_initEnvironmentFunc)aMod.getSymbol(aSymbolName); if (!fpInit) - { - ::osl_unloadModule( hMod ); return false; - } + + aMod.release(); #endif (*fpInit)( pEnv ); // init of environment diff --git a/cppu/source/uno/lbmap.cxx b/cppu/source/uno/lbmap.cxx index a887f899a8dd..03130228c431 100644 --- a/cppu/source/uno/lbmap.cxx +++ b/cppu/source/uno/lbmap.cxx @@ -337,7 +337,7 @@ static uno_ext_getMappingFunc selectMapFunc( const OUString & rBridgeName ) #else -static inline oslModule loadModule( const OUString & rBridgeName ) +static inline bool loadModule(osl::Module & rModule, const OUString & rBridgeName) { bool bNeg; { @@ -347,16 +347,16 @@ static inline oslModule loadModule( const OUString & rBridgeName ) bNeg = (iFind != rData.aNegativeLibs.end()); } - if (! bNeg) + if (!bNeg) { - oslModule hModule = cppu::detail::loadModule( rBridgeName ); + bool bModule = cppu::detail::loadModule(rModule, rBridgeName); - if (hModule) - return hModule; + if (bModule) + return true; setNegativeBridge( rBridgeName ); // no load again } - return 0; + return false; } #endif @@ -406,22 +406,22 @@ static Mapping loadExternalMapping( } #else // find proper lib - oslModule hModule = 0; + osl::Module aModule; + bool bModule; OUString aName; if ( EnvDcp::getTypeName(rFrom.getTypeName()) == UNO_LB_UNO ) - hModule = loadModule( aName = getBridgeName( rTo, rFrom, rAddPurpose ) ); - if (! hModule) - hModule = loadModule( aName = getBridgeName( rFrom, rTo, rAddPurpose ) ); - if (! hModule) - hModule = loadModule( aName = getBridgeName( rTo, rFrom, rAddPurpose ) ); + bModule = loadModule( aModule, aName = getBridgeName( rTo, rFrom, rAddPurpose ) ); + if (!bModule) + bModule = loadModule( aModule, aName = getBridgeName( rFrom, rTo, rAddPurpose ) ); + if (!bModule) + bModule = loadModule( aModule, aName = getBridgeName( rTo, rFrom, rAddPurpose ) ); - if (hModule) + if (bModule) { OUString aSymbolName( UNO_EXT_GETMAPPING ); uno_ext_getMappingFunc fpGetMapFunc = - (uno_ext_getMappingFunc)::osl_getFunctionSymbol( - hModule, aSymbolName.pData ); + (uno_ext_getMappingFunc)aModule.getSymbol( aSymbolName ); if (fpGetMapFunc) { @@ -430,10 +430,11 @@ static Mapping loadExternalMapping( OSL_ASSERT( aExt.is() ); if (aExt.is()) { + aModule.release(); return aExt; } } - ::osl_unloadModule( hModule ); + aModule.unload(); setNegativeBridge( aName ); } #endif diff --git a/cppu/source/uno/loadmodule.cxx b/cppu/source/uno/loadmodule.cxx index f00936d328d2..1d8ab7576a67 100644 --- a/cppu/source/uno/loadmodule.cxx +++ b/cppu/source/uno/loadmodule.cxx @@ -31,16 +31,16 @@ namespace cppu { namespace detail { #ifndef DISABLE_DYNLOADING -::oslModule loadModule(rtl::OUString const & name) { +bool loadModule(osl::Module& rModule, rtl::OUString const & name) { rtl::OUStringBuffer b; #if defined SAL_DLLPREFIX b.append(SAL_DLLPREFIX); #endif b.append(name); b.append(SAL_DLLEXTENSION); - return ::osl_loadModuleRelative( + return rModule.loadRelative( reinterpret_cast< oslGenericFunction >(&loadModule), - b.makeStringAndClear().pData, + b.makeStringAndClear(), SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY); } diff --git a/cppu/source/uno/loadmodule.hxx b/cppu/source/uno/loadmodule.hxx index 1062799f00c9..a87c7b1ac3a1 100644 --- a/cppu/source/uno/loadmodule.hxx +++ b/cppu/source/uno/loadmodule.hxx @@ -21,7 +21,7 @@ #define INCLUDED_CPPU_SOURCE_UNO_LOADMODULE_HXX #include "sal/config.h" -#include "osl/module.h" +#include <osl/module.hxx> namespace rtl { class OUString; } @@ -35,10 +35,9 @@ namespace cppu { namespace detail { the nucleus of a module name (without any "lib...so", ".dll", etc. decoration, and without a path). - @return - the handle returned by osl_loadModule. + @return false if the module could not be loaded, otherwise true */ -::oslModule loadModule(::rtl::OUString const & name); +bool loadModule(osl::Module & rModule, ::rtl::OUString const & name); #endif |