diff options
author | Haru <haru@dotalux.com> | 2016-10-14 00:05:07 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-10-14 00:12:49 +0200 |
commit | b664a9fe58c26323699bb7f3798092491fd3bd12 (patch) | |
tree | ca550a7255f93bd9430bf2a96c525de97392148e | |
parent | b75799528a1394919fd5eb4c8763a96ee80a9325 (diff) | |
download | hercules-b664a9fe58c26323699bb7f3798092491fd3bd12.tar.gz hercules-b664a9fe58c26323699bb7f3798092491fd3bd12.tar.bz2 hercules-b664a9fe58c26323699bb7f3798092491fd3bd12.tar.xz hercules-b664a9fe58c26323699bb7f3798092491fd3bd12.zip |
Fixed a memory manager crash when a memory leak occurs in a plugin
- Plugins were accidentally using the core's memory manager instead of
the HPM-safe wrappers.
- As a side-effect of this, plugins shall not be able to hook into the
iMalloc interface.
- The issue was introduced in e7c2f7d827ad286dc826e483391e64b8ffe2720b
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/common/HPM.c | 3 | ||||
-rw-r--r-- | src/common/HPMi.h | 1 | ||||
-rw-r--r-- | src/common/memmgr.h | 4 | ||||
-rwxr-xr-x | tools/HPMHookGen/HPMHookGen.pl | 3 |
4 files changed, 7 insertions, 4 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index ff1371b14..1fad7102f 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -567,6 +567,7 @@ struct hplugin *hplugin_load(const char* filename) /* id */ plugin->hpi->pid = plugin->idx; /* core */ + plugin->hpi->memmgr = HPMiMalloc; #ifdef CONSOLE_INPUT plugin->hpi->addCPCommand = console->input->addCommand; #endif // CONSOLE_INPUT @@ -1093,8 +1094,8 @@ void hpm_init(void) HPM->off = false; - memcpy(&iMalloc_HPM, iMalloc, sizeof(struct malloc_interface)); HPMiMalloc = &iMalloc_HPM; + *HPMiMalloc = *iMalloc; HPMiMalloc->malloc = HPM_mmalloc; HPMiMalloc->calloc = HPM_calloc; HPMiMalloc->realloc = HPM_realloc; diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 19b9b20a5..143c325c1 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -231,6 +231,7 @@ struct HPMi_interface { /* Hooking */ struct HPMHooking_interface *hooking; + struct malloc_interface *memmgr; }; #ifdef HERCULES_CORE #define HPM_SYMBOL(n, s) (HPM->share((s), (n)), true) diff --git a/src/common/memmgr.h b/src/common/memmgr.h index 680947466..a5b7e4e7d 100644 --- a/src/common/memmgr.h +++ b/src/common/memmgr.h @@ -101,8 +101,10 @@ struct malloc_interface { void malloc_defaults(void); void memmgr_report(int extra); -#endif // HERCULES_CORE HPShared struct malloc_interface *iMalloc; +#else +#define iMalloc HPMi->memmgr +#endif // HERCULES_CORE #endif /* COMMON_MEMMGR_H */ diff --git a/tools/HPMHookGen/HPMHookGen.pl b/tools/HPMHookGen/HPMHookGen.pl index 3203e0b70..b8835b376 100755 --- a/tools/HPMHookGen/HPMHookGen.pl +++ b/tools/HPMHookGen/HPMHookGen.pl @@ -295,6 +295,7 @@ foreach my $file (@files) { # Loop through the xml files my $loc = $data->{compounddef}->{$filekey}->{location}->[0]; next unless $loc->{file} =~ /src\/(map|char|login|common)\//; next if $loc->{file} =~ /\/HPM.*\.h/; # Don't allow hooking into the HPM itself + next if $loc->{file} =~ /\/memmgr\.h/; # Don't allow hooking into the memory manager my $servertype = $1; my $key = $data->{compounddef}->{$filekey}->{compoundname}->[0]; my $original = $key; @@ -338,8 +339,6 @@ foreach my $file (@files) { # Loop through the xml files $key = "chr"; } elsif ($key eq "db_interface") { $key = "DB"; - } elsif ($key eq "malloc_interface") { - $key = "iMalloc"; } elsif ($key eq "socket_interface") { $key = "sockt"; } elsif ($key eq "sql_interface") { |