2016-10-05 4 views
2

Ich laufe und Analyse mit Valgrind diesen Code:kann nicht Speicherverlust von Valgrind erkannt finden

int main() { 
    Set<int> c; 
    return 0; 
} 

So ist der Ausgang:

[email protected]:~/ClionProjects/algo2-t3-bts$ g++ set.hpp tests.cpp && valgrind --leak-check=yes --show-leak-kinds=all ./a.out 
==3528== Memcheck, a memory error detector 
==3528== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. 
==3528== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info 
==3528== Command: ./a.out 
==3528== 
test_mleak...ok 
==3528== 
==3528== HEAP SUMMARY: 
==3528==  in use at exit: 72,704 bytes in 1 blocks 
==3528== total heap usage: 2 allocs, 1 frees, 73,728 bytes allocated 
==3528== 
==3528== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1 
==3528== at 0x4C2DC10: malloc (vg_replace_malloc.c:299) 
==3528== by 0x4EC3EFF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) 
==3528== by 0x40104E9: call_init.part.0 (dl-init.c:72) 
==3528== by 0x40105FA: call_init (dl-init.c:30) 
==3528== by 0x40105FA: _dl_init (dl-init.c:120) 
==3528== by 0x4000CF9: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so) 
==3528== 
==3528== LEAK SUMMARY: 
==3528== definitely lost: 0 bytes in 0 blocks 
==3528== indirectly lost: 0 bytes in 0 blocks 
==3528==  possibly lost: 0 bytes in 0 blocks 
==3528== still reachable: 72,704 bytes in 1 blocks 
==3528==   suppressed: 0 bytes in 0 blocks 
==3528== 
==3528== For counts of detected and suppressed errors, rerun with: -v 
==3528== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 

Offenbar ich verliere die Erinnerung an der Konstruktor von Set, aber ich kann den tatsächlichen Grund nicht finden. Dies ist, wie ich implementiert Set (in einem BTS):

template<class T> 
class Set { 
public: 
    Set() : root_(NULL), cardinal_(0) {} 
    ~Set() {delete root_;} 
    void insert(const T &); 
    bool belongs(const T &) const; 
    void remove(const T &); 
    const T &min() const; 
    const T &max() const; 
    unsigned int cardinal() const; 

private: 

    struct Node { 
     Node(const T &v) : value(v), left(NULL), right(NULL) {} 
     ~Node() {delete right; delete left;} 
     T value; 
     Node *left; 
     Node *right; 
    }; 

    Node *root_; 
    int cardinal_; 
} 

Jede Idee, wie dieses Leck zu lösen? Vielen Dank!

Antwort

3

Sie lassen nichts durch - Sie verstehen nur, was Valgrind Ihnen sagt.

Es denkt, es könnte ein Problem unter _dl_init() sein, aber das ist ein Red Hering. Sie können es sicher zu Ihrer Valgrind-Unterdrückungsdatei hinzufügen (was immer eine gute Sache ist, damit Sie nicht durch falsche Alarme von Systembibliotheken belästigt werden).

Verwandte Themen