Valgrind complains about the line with new (the first one):
#ifndef MAXI_BUF_SIZE
#define MAXI_BUF_SIZE 2*8192
#endif
if (lg_maxi_buf == NULL)
{
lg_maxi_buf = new unsigned char[MAXI_BUF_SIZE] ;
}
else
{
delete [] lg_maxi_buf ;
lg_maxi_buf = NULL ;
lg_maxi_buf = new unsigned char[MAXI_BUF_SIZE] ;
}
I wanted to explain that the field lg_maxi_buf
is part of class Audio_decoder and it is declared like this:
unsigned char *lg_maxi_buf;
in the constructor of the class Audio_decoder lg_maxi_buf
is initialized in this way:
lg_maxi_buf = NULL;
Thanks for your answers. I think I will have to use smart pointers, but my knowledge on them is very poor.
you could simplify your if-else in
The delete operator ignores NULL parameters (you avoid many
if
s that way. I personally don't affect NULL prior a new, but I understand if you prefer.To initialize this bloc of memory, just add parenthesis: