#include "../lib/irc_string.h"
#include "../lib/splitline.h"
#include "../lib/strlfunc.h"
+#include "../lib/valgrind.h"
#include "config.h"
#include "error.h"
#include <stdio.h>
}
-int rmmod(char *modulename) {
+int rmmod(char *modulename, int close) {
int i,j;
module *mods;
struct module_dep *mdp;
if ((mdp=getmoduledep(modulebuf))) {
for (j=0;j<mdp->numchildren;j++) {
if (isloaded(mdp->children[j]->name->content)) {
- if (rmmod(mdp->children[j]->name->content)) {
+ if (rmmod(mdp->children[j]->name->content, close)) {
Error("core",ERR_WARNING,"Unable to remove child module %s (depends on %s)",
mdp->children[j]->name->content, modulebuf);
return 1;
mods=(module *)(modules.content);
+ if (!close
#ifdef BROKEN_DLCLOSE
- {
+ || 1
+#endif
+ ) {
void (*fini)();
fini = dlsym(mods[i].handle, "__fini");
if(!dlerror())
fini();
- }
-#endif
+ } else
+ dlclose(mods[i].handle);
- dlclose(mods[i].handle);
freesstring(mods[i].name);
array_delslot(&modules,i);
return;
preparereload(safereload_str->content);
- rmmod(safereload_str->content);
+ rmmod(safereload_str->content, 1);
insmod(safereload_str->content);
reloadmarked();
mods=(module *)(modules.content);
strlcpy(buf, mods[0].name->content, sizeof(buf));
- rmmod(buf);
+
+ /* Unload the module unless we're running on Valgrind -
+ * in which case unloading the module would invalidate
+ * stacktraces Valgrind has captured so far. */
+ rmmod(buf, !RUNNING_ON_VALGRIND);
}
clearmoduledeps();