lundi 1 juin 2015

Resolving memory leak that occured using unique_ptr

I have a cl.h file as follows :

class CCTB{
  private:
    std::unique_ptr<tj> buffer;
}

And cl.cpp file containing this function :

void CCTB::Ensure(Args* pArgs)
{
  if (NULL == buffer.get())
  {
    // loadBuffer returns a std::unique_ptr<tj>
    buffer = loadBuffer();
    pArgs->iHeaders.push_back(m_cthBuffer.get()->getBuffer().data());
  }
}

When I run umdh on this it shows me that I have a memory leak on line 5 of my cl.cpp file i.e. buffer = loadBuffer();. Can anyone help me figuring out why? I have been banging my head against this code for 2 days but can't find the reason.

I tried putting printf messages in the constructor and destructor of class tj, and they do get called.

Aucun commentaire:

Enregistrer un commentaire