2012-04-04 2 views
2

Je vérifie mon code pour les fuites de mémoire. Tout va bien jusqu'à ce que je le code:Valgrind détection de fuite avec segfault

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

SetView fait son travail vraiment minuscule (extraits quelques membres du passé pointeur view Lorsque dernière ligne de code est tout commentaire est correct, mais tout décommentant fonctionne en mode par défaut et échoue. dans la détection de fuites mémoire avec 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. 

Les questions sont les suivantes:. Pourquoi faut-il fonctionne avec succès sans valgrind et rompt avec elle j'ai aussi essayé de mettre --main-stacksize= une grande valeur, mais il n'a pas aidé. moi

+3

Cela ne fonctionne probablement pas sans valgrind. Il devient un comportement indéfini parce que vous utilisez un pointeur invalide, ce qui signifie que tout peut arriver. –

+0

N'oubliez pas que le problème n'a pas à être lié à la ligne 'mSystem-> SetView (* view); Vous avez peut-être corrompu n'importe où dans la mémoire à tout moment avant ce point. Valgrind pourrait bien être en train de changer où sont les choses ... – enobayram

Répondre

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

À un certain moment (probablement LightSystem.cpp:55) vous êtes déréférencement d'un pointeur auquel vous avez attribué 8 qui ne ressemble en rien une adresse valide.

+0

Donc, c'est étrange, j'ai vérifié tous les pointeurs ('view' avant et après) et tout semble bien se passer – Ockonal

Questions connexes