2012-04-04 217 views
2

我檢查我的代碼內存泄漏。一切正常,直到我得到的代碼:Valgrind漏洞檢測與段錯誤

mSystem = new LightSystem(); 
sf::View *view = th::DisplayManager::Get()->GetCamera(); 
mSystem->SetView(*view); 

SetView確實真的很小作業(提取物通過view指針的一些成員在最新的代碼行註釋掉一切正常,但在取消一切工作在默認模式和失敗。在內存泄漏檢測與的valgrind(valgrind --tool=memcheck ./Binary

==23703== Use of uninitialised value of size 8 
==23703== at 0x6B8472: ltbl::LightSystem::SetView(sf::View const&) (LightSystem.cpp:55) 
==23703== by 0x6A7A7D: th::LightManager::Initialize() (LightManager.cpp:46) 
==23703== by 0x6A75EA: th::Root::Initialize() (Root.cpp:101) 
==23703== by 0x6A7113: th::Root::Root() (Root.cpp:66) 
==23703== by 0x6A7553: th::Root::Get() (Root.cpp:88) 
==23703== by 0x6291A8: th::Game::Initialize() (Game.cpp:36) 
==23703== by 0x61DC1C: main (main.cpp:82) 
==23703== 
==23703== Invalid read of size 8 
==23703== at 0x6B8472: ltbl::LightSystem::SetView(sf::View const&) (LightSystem.cpp:55) 
==23703== by 0x6A7A7D: th::LightManager::Initialize() (LightManager.cpp:46) 
==23703== by 0x6A75EA: th::Root::Initialize() (Root.cpp:101) 
==23703== by 0x6A7113: th::Root::Root() (Root.cpp:66) 
==23703== by 0x6A7553: th::Root::Get() (Root.cpp:88) 
==23703== by 0x6291A8: th::Game::Initialize() (Game.cpp:36) 
==23703== by 0x61DC1C: main (main.cpp:82) 
==23703== Address 0x8 is not stack'd, malloc'd or (recently) free'd 
==23703== 
==23703== 
==23703== Process terminating with default action of signal 11 (SIGSEGV) 
==23703== Access not within mapped region at address 0x8 
==23703== at 0x6B8472: ltbl::LightSystem::SetView(sf::View const&) (LightSystem.cpp:55) 
==23703== by 0x6A7A7D: th::LightManager::Initialize() (LightManager.cpp:46) 
==23703== by 0x6A75EA: th::Root::Initialize() (Root.cpp:101) 
==23703== by 0x6A7113: th::Root::Root() (Root.cpp:66) 
==23703== by 0x6A7553: th::Root::Get() (Root.cpp:88) 
==23703== by 0x6291A8: th::Game::Initialize() (Game.cpp:36) 
==23703== by 0x61DC1C: main (main.cpp:82) 
==23703== If you believe this happened as a result of a stack 
==23703== overflow in your program's main thread (unlikely but 
==23703== possible), you can try to increase the size of the 
==23703== main thread stack using the --main-stacksize= flag. 
==23703== The main thread stack size used in this run was 8388608. 

的問題是:爲什麼它的工作原理沒有成功的valgrind和休息吧 我也試圖設置--main-stacksize=一個很大的價值,但它並沒有幫助。我

+3

如果沒有valgrind,它可能不會「工作」。這是因爲你使用了一個無效指針而導致未定義的行爲,這意味着任何事情都可能發生。 – 2012-04-04 12:19:14

+0

不要忘記,問題不必與'mSystem-> SetView(* view);'行相關。在該點之前的任何時候,您可能會在內存中的任何地方損壞。 Valgrind可能只是改變的地方... – enobayram 2012-04-04 12:20:50

回答

4
==23703== Process terminating with default action of signal 11 (SIGSEGV) 
==23703== Access not within mapped region at address 0x8 

在某些時候(可能LightSystem.cpp:55)你解引用指針您分配8它看起來完全不像一個有效的地址。

+0

很奇怪,我已經檢查過所有的指針(前後都是'view'),一切似乎都沒問題 – Ockonal 2012-04-04 12:23:52