Hello everyone,
I'm writing a program using the id3lib unfortunately I've encountered with memory issue that cause segmentation fault. I tried to rerun and analyze the program with valgrind but it doesn't point me anywhere. I really stuck on this one.
Valgrind output:
==14716== Invalid read of size 4
==14716== at 0x404BEFC: ID3_Frame::GetField(ID3_FieldID) const (in /usr/lib/libid3-3.8.so.3.0.0)
==14716== by 0x8049BD0: Parse_mask(char const*, char const*, ID3_TagType) (in /home/earlcash/dev/id3fcp/id3fcp)
==14716== by 0x804967D: main (in /home/earlcash/dev/id3fcp/id3fcp)
==14716== Address 0x4 is not stack'd, malloc'd or (recently) free'd
==14716==
==14716== Process terminating with default action of signal 11 (SIGSEGV)
==14716== Access not within mapped region at address 0x4
==14716== at 0x404BEFC: ID3_Frame::GetField(ID3_FieldID) const (in /usr/lib/libid3-3.8.so.3.0.0)
==14716== by 0x8049BD0: Parse_mask(char const*, char const*, ID3_TagType) (in /home/earlcash/dev/id3fcp/id3fcp)
==14716== by 0x804967D: main (in /home/earlcash/dev/id3fcp/id3fcp)
==14716==
==14716== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 21 from 1)
==14716== malloc/free: in use at exit: 775 bytes in 6 blocks.
==14716== malloc/free: 16 allocs, 10 frees, 9,487 bytes allocated.
==14716== For counts of detected errors, rerun with: -v
==14716== searching for pointers to 6 not-freed blocks.
==14716== checked 130,888 bytes.
'Parse_mask' definition:
const char *Parse_mask(const char *filename, const char *mask, ID3_TagType id3_ver){
p_symbols event[] =
{
{ "%n", ID3FID_TRACKNUM },
{ "%i", ID3FID_ORIGARTIST },
{ "%t", ID3FID_TITLE },
{ "%a", ID3FID_ALBUM },
// { "%g", ID3FID_ },
{ "%y", ID3FID_ORIGYEAR },
// { "%c", },
{ NULL, ID3FID_NOFRAME }
};
string s_mask = mask;
ID3_Tag file;
/*ID3_Frame *f_frame = NULL;
ID3_Field *f_field = NULL;*/
char tag_buff[255];
int iter = 0;
size_t match;
if(file.Link(filename, id3_ver) == 0){
return NULL;
}
while(event[iter].symbol != NULL){
if((match = s_mask.find(event[iter].symbol)) != string::npos){
file.Find(event[iter].frame_id)->GetField(ID3FN_TEXT)->Get(tag_buff, 255);
s_mask.replace(match, strlen(event[iter].symbol), tag_buff);
iter++;
continue;
}
iter++;
}
file.Clear();
s_mask += ".mp3";
return s_mask.c_str();
}
Thanks in advance