[Flac-dev] Memory leak using libflac++

Andy Hawkins andy at gently.org.uk
Sat Jun 11 04:22:28 PDT 2011


Hi,

In article <BANLkTi=L+XNe3zVRoVMzSYvCwVhtpNh7xQ at mail.gmail.com>,
           Stephen F. Booth<me at sbooth.org> wrote:
> I've never used the C++ API, but the source for get_block() is just:
>
>     return local::construct_block(::FLAC__metadata_simple_iterator_get_block(iterator_));
>
> and construct_block() looks like (simplified for the picture case):
>
>     Prototype *ret = 0;
>     ret = new Picture(object, /*copy=*/false);
>     return ret;
>
> So I don't see any way this couldn't be a leak if you aren't deleting
> the pointer returned from get_block().
>
> The documentation says:
>
>     *  The ownership of pointers in the C++ layer follows that in
>     *  the C layer, i.e.
>     *    - The objects returned by get_block() are yours to
>     *      modify, but changes are not reflected in the FLAC file
>     *      until you call set_block().  The objects are also
>     *      yours to delete; they are not automatically deleted
>     *      when passed to set_block() or insert_block_after().
>
> So I think it will be necessary for you to delete the object manually.

Thanks for that. Can't find all of that in the documentation I'm looking at:

http://flac.sourceforge.net/api/index.html

However, it does all make sense and ties in with my reading of the library
source too.

Thanks a lot for the response.

Andy



More information about the Flac-dev mailing list