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
#include <FLAC++/metadata.h>
#include <iostream>
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "Need flac argument" << std::endl;
return 1;
}
FLAC::Metadata::Chain chain;
chain.read(argv[1]);
FLAC::Metadata::Iterator iterator;
iterator.init(chain);
FLAC::Metadata::Prototype *prot = iterator.get_block();
// delete prot; // this fixes it
chain.write();
return 0;
}
_______________________________________________
flac-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/flac-dev