[flac-dev] Slight memory leak or bad documentation

Bastiaan Timmer basjetimmer at yahoo.com
Tue Jul 9 08:28:33 PDT 2013


Hi, I was just messing around with a metadata modifier in flac (using the C++ api) and found something strange.

When iterating over a chain and calling FLAC::Metadata::Iterator::get_block(), it seems a newly constructed ProtoType* is returned (the source says "return local::construct(::FLAC__metadata_simple_iterator_get_block(iterator_));"), if one does not delete this pointer, the program leaks memory (see attached example, run it through valgrind).

However the documentation for get_block() only refers to the C API function FLAC__metadata_iterator_get_block(), which expilicitly states: "Do not call FLAC__metadata_object_delete() on the returned object".

I don't see an easy way to change get_block() to return a pointer which wouldn't require deleting (as the underlying C function doesn't return a pointer to a C++ object), so I think the documentation for the FLAC++ API should be changed to say that the user is required to delete the pointer returned by get_block(). Does this seem correct? Or is there a danger in deleting the new object as its internal FLAC__StreamMetadata* is still used?


thanks,
Bas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cc
Type: text/x-c++src
Size: 422 bytes
Desc: not available
Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20130709/acf115ef/attachment.cc 


More information about the flac-dev mailing list