diff options
| author | 2007-04-21 23:16:20 +0000 | |
|---|---|---|
| committer | 2007-04-21 23:16:20 +0000 | |
| commit | 4e394a6302942f9a418b30c0e40059ef38e963a2 (patch) | |
| tree | 4e4d11d574571591fcac11370f2867698abbf17b /src/modules | |
| parent | clearing recent channels properly (diff) | |
| download | KVIrc-4e394a6302942f9a418b30c0e40059ef38e963a2.tar.gz KVIrc-4e394a6302942f9a418b30c0e40059ef38e963a2.tar.bz2 KVIrc-4e394a6302942f9a418b30c0e40059ef38e963a2.zip | |
crash fix + a bit more doc
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@523 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/system/plugin.cpp | 55 | ||||
| -rw-r--r-- | src/modules/system/plugin.h | 3 |
2 files changed, 56 insertions, 2 deletions
diff --git a/src/modules/system/plugin.cpp b/src/modules/system/plugin.cpp index faff43612..2c53191f2 100644 --- a/src/modules/system/plugin.cpp +++ b/src/modules/system/plugin.cpp @@ -46,6 +46,42 @@ Small plugins which can be called in scripts @body: TODO + [b]Exported functions by dll[/b][br] + [br]_free function (needed)[br] + [example] + int _free(void * p)[br] + {[br] + // Always free the memory here![br] + free(p);[br] + return 0;[br] + }[br] + [/example] + + [br]_load function (optional)[br] + [example] + int _load()[br] + {[br] + return 0;[br] + }[br] + [/example] + + [br]_unload function (optional)[br] + [example] + int _unload()[br] + {[br] + return 0;[br] + }[br] + [/example] + + [br]user function[br] + [example] + int about(int argc, char * argv[], char ** pBuffer)[br] + {[br] + *pBuffer = (char*)malloc(1024);[br] + sprintf((char*)*pBuffer, "Hello World"); [br] + return 1;[br] + }[br] + [/example] */ KviPlugin::KviPlugin(kvi_library_t pLib, const QString& name) @@ -79,6 +115,20 @@ KviPlugin* KviPlugin::load(const QString& szFileName) return pPlugin; } +bool KviPlugin::pfree(char * pBuffer) +{ + plugin_free function_free; + + function_free = (plugin_free)kvi_library_symbol(m_Plugin,"_free"); + if (function_free) + { + //TODO: THREAD + function_free(pBuffer); + return true; + } + return false; +} + bool KviPlugin::unload(bool forced) { plugin_unload function_unload; @@ -238,7 +288,10 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) //Clean up free(pArgvBuffer); free(ppArgv); - free(returnBuffer); + if (!plugin->pfree(returnBuffer)) + { + c->warning(__tr2qs("The plugin has no function to free memory. Can result in Memory Leaks!")); + } return true; } diff --git a/src/modules/system/plugin.h b/src/modules/system/plugin.h index c931a59c5..cd6002e5c 100644 --- a/src/modules/system/plugin.h +++ b/src/modules/system/plugin.h @@ -32,6 +32,7 @@ typedef int (*plugin_function)(int argc, char* argv[], char ** buffer); typedef int (*plugin_unload)(); typedef int (*plugin_load)(); +typedef int (*plugin_free)(char * pBuffer); class KviPlugin { @@ -47,7 +48,7 @@ private: QString m_szName; public: static KviPlugin* load(const QString& szFileName); - + bool pfree(char * pBuffer); bool unload(bool forced); int call(const QString& szFunctionName, int argc, char * argv[], char ** pBuffer); QString name(); |
