2012-04-04 212 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