aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/system/plugin.cpp
diff options
context:
space:
mode:
authorGravatar TheXception2007-04-21 23:16:20 +0000
committerGravatar TheXception2007-04-21 23:16:20 +0000
commit4e394a6302942f9a418b30c0e40059ef38e963a2 (patch)
tree4e4d11d574571591fcac11370f2867698abbf17b /src/modules/system/plugin.cpp
parentclearing recent channels properly (diff)
downloadKVIrc-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/system/plugin.cpp')
-rw-r--r--src/modules/system/plugin.cpp55
1 files changed, 54 insertions, 1 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;
}