aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnubisss <none@none>2010-05-13 14:15:11 +0200
committerAnubisss <none@none>2010-05-13 14:15:11 +0200
commit10bf921a65a6f040b6a404609752852e03760a95 (patch)
tree55f221597c5f90024945b105474115656d2a9f68
parente7faef7e76edd84ccdf75139ef78a697db28ad04 (diff)
Generate an error message when core tries to assign a script's ScriptName which is already assigned.
This means if that happened the core override the older script. As a result, the earlier one doesn't work and can't deallocate so generates memory leak. This commit also fixes memory leaks caused by that. Valgrind log: ==4753== 354 (312 direct, 42 indirect) bytes in 1 blocks are definitely lost in loss record 1,194 of 1,218 ==4753== at 0x4C2626C: operator new(unsigned long) (vg_replace_malloc.c:230) ==4753== by 0x1039D85: AddSC_go_scripts() (go_scripts.cpp:1015) ==4753== by 0xDC196F: AddScripts() (ScriptLoader.cpp:534) ==4753== by 0xC19943: ScriptMgr::ScriptsInit() (ScriptMgr.cpp:70) ==4753== by 0xD1CCAE: World::SetInitialWorldSettings() (World.cpp:1608) ==4753== by 0x9100A6: Master::Run() (Master.cpp:234) ==4753== by 0x90F5D6: main (Main.cpp:146) --HG-- branch : trunk
-rw-r--r--src/game/ScriptMgr.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp
index 26609430e27..05dc57f2a00 100644
--- a/src/game/ScriptMgr.cpp
+++ b/src/game/ScriptMgr.cpp
@@ -161,8 +161,34 @@ void Script::RegisterSelf()
int id = GetScriptId(Name.c_str());
if (id)
{
- m_scripts[id] = this;
- ++num_sc_scripts;
+ // try to find the script in assigned scripts
+ bool IsExist = false;
+ for (uint16 i = 0; i < MAX_SCRIPTS; ++i)
+ {
+ if (m_scripts[i])
+ {
+ // if the assigned script's name and the new script's name is the same
+ if (m_scripts[i]->Name == Name)
+ {
+ IsExist = true;
+ break;
+ }
+ }
+ }
+
+ // if the script doesn't assigned -> assign it!
+ if (!IsExist)
+ {
+ m_scripts[id] = this;
+ ++num_sc_scripts;
+ }
+ // if the script is already assigned -> delete it!
+ else
+ {
+ // TODO: write a better error message than this one :)
+ error_log("ScriptName: '%s' already assigned with the same ScriptName, so the script can't work.", Name.c_str());
+ delete this;
+ }
}
else
{