From 4e394a6302942f9a418b30c0e40059ef38e963a2 Mon Sep 17 00:00:00 2001 From: TheXception Date: Sat, 21 Apr 2007 23:16:20 +0000 Subject: crash fix + a bit more doc git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@523 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/system/plugin.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'src/modules/system/plugin.cpp') 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; } -- cgit v1.3.1-10-gc9f91