Why does this leak?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why does this leak?

djczaski
My first try at using libxspf:

    class Foo : public Xspf::XspfReaderCallback
    {
        void setProps(Xspf::XspfProps *props)
        {
            printf("Props\n");
            printf("    getTitle %s\n", props->getTitle());

            delete props;
        }

        void addTrack(Xspf::XspfTrack *track)
        {
            printf("Track\n");
            printf("    getTitle %s\n", track->getTitle());

            if (track->getLocationCount() > 0)
                printf("    getLocation(0) %s\n", track->getLocation(0));

            delete track;
        }
    };

    int main(int argc, char *argv[])
    {
        Xspf::XspfReader reader;
        Foo foo;

        reader.parseFile(argv[1], &foo, _PT("http://example.org/"));

        return 0;
    }

And I feed this a simple XSPF file:

    <?xml version="1.0" encoding="UTF-8"?>
    <playlist version="1" xmlns="http://xspf.org/ns/0/">
        <title>playlist title</title>
        <creator>playlist creator</creator>
        <trackList>
            <track>
                <location>http://example.com/song_1.mp3</location>
                <creator>Artist 1</creator>
                <album>Album 1</album>
                <title>Title 1</title>
                <annotation>Annotation 1</annotation>
                <duration>271066</duration>

<image>http://images.amazon.com/images/P/B000002J0B.01.MZZZZZZZ.jpg</image>
                <info>http://example.com</info>
            </track>
        </trackList>
    </playlist>

And run it through valgrind and there are two leaks:

    ==6287== Memcheck, a memory error detector
    ==6287== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
    ==6287== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h
for copyright info
    ==6287== Command: ./test ../playlist/test-files/xspf/simple2.xspf
    ==6287==
    Track
        getTitle Title 1
        getLocation(0) http://example.com/song_1.mp3
    Props
        getTitle playlist title
    ==6287==
    ==6287== HEAP SUMMARY:
    ==6287==     in use at exit: 80 bytes in 2 blocks
    ==6287==   total heap usage: 100 allocs, 98 frees, 11,982 bytes allocated
    ==6287==
    ==6287== 19 bytes in 1 blocks are definitely lost in loss record 1 of 2
    ==6287==    at 0x402532E: operator new[](unsigned int)
(vg_replace_malloc.c:299)
    ==6287==    by 0x404D110: Xspf::Toolbox::(anonymous
namespace)::allocTransformUri(char const*, char const*, bool)
(XspfToolbox.cpp:209)
    ==6287==    by 0x40455D3: Xspf::XspfReader::makeAbsoluteUri(char
const*) const (XspfReader.cpp:555)
    ==6287==    by 0x4045DEF: Xspf::XspfReader::handleEndFour(char
const*) (XspfReader.cpp:1943)
    ==6287==    by 0x404A727: Xspf::XspfReader::handleEnd(char const*)
(XspfReader.cpp:2074)
    ==6287==    by 0x404AAF3: Xspf::XspfReader::masterEnd(void*, char
const*) (XspfReader.cpp:2553)
    ==6287==    by 0x4335CFD: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4336BC0: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4338412: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4338CD9: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4331F02: XML_ParseBuffer (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4047410: Xspf::XspfReader::parseFile(char const*,
Xspf::XspfReaderCallback*, char const*) (XspfReader.cpp:619)
    ==6287==
    ==6287== 61 bytes in 1 blocks are definitely lost in loss record 2 of 2
    ==6287==    at 0x402532E: operator new[](unsigned int)
(vg_replace_malloc.c:299)
    ==6287==    by 0x404D110: Xspf::Toolbox::(anonymous
namespace)::allocTransformUri(char const*, char const*, bool)
(XspfToolbox.cpp:209)
    ==6287==    by 0x40455D3: Xspf::XspfReader::makeAbsoluteUri(char
const*) const (XspfReader.cpp:555)
    ==6287==    by 0x4045DAF: Xspf::XspfReader::handleEndFour(char
const*) (XspfReader.cpp:1931)
    ==6287==    by 0x404A727: Xspf::XspfReader::handleEnd(char const*)
(XspfReader.cpp:2074)
    ==6287==    by 0x404AAF3: Xspf::XspfReader::masterEnd(void*, char
const*) (XspfReader.cpp:2553)
    ==6287==    by 0x4335CFD: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4336BC0: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4338412: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4338CD9: ??? (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4331F02: XML_ParseBuffer (in /lib/libexpat.so.1.5.2)
    ==6287==    by 0x4047410: Xspf::XspfReader::parseFile(char const*,
Xspf::XspfReaderCallback*, char const*) (XspfReader.cpp:619)
    ==6287==
    ==6287== LEAK SUMMARY:
    ==6287==    definitely lost: 80 bytes in 2 blocks
    ==6287==    indirectly lost: 0 bytes in 0 blocks
    ==6287==      possibly lost: 0 bytes in 0 blocks
    ==6287==    still reachable: 0 bytes in 0 blocks
    ==6287==         suppressed: 0 bytes in 0 blocks
    ==6287==
    ==6287== For counts of detected and suppressed errors, rerun with: -v
    ==6287== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 24 from 7)

I deleted the tracks and props.  What is missing here?

_______________________________________________
Playlist mailing list
[hidden email]
http://lists.musicbrainz.org/mailman/listinfo/playlist
Loading...