I am trying to make a music player using TagLib library (1.11.1) in Qt5 C++. I opened multiple files and read tags. And I encountered with two difficulties. After opening a file and reading the tags I couldn't close the file and deallocate memory occupied by the file. I used delete
to free up memory and close the file. But when I try this the program crashes. Here is snip code of my program:
QString audioPath("song.mp3")
auto file = new MPEG::File(audioPath.toStdWString().c_str());
if (file->isOpen()) {
auto tag = file->ID3v2Tag();
if (tag) {
//read audio tags
}
}
delete file;
When I remove
delete file;
it works perfect but there is memory leakage special when opening multiple files.If I opened a file I couldn't open it again because there is no way to close the opened file without exiting the program. And leaves me with this error:
TagLib: Could not open file song.mp3
Is there a way to solve the memory leak and close the opened file?
And when I run debugging with delete file;
I see this message:
The inferior stopped because it received a signal from the operating system.
Signal name: SIGSEGV
Signal meaning: Segmentation fault