Archived Forum Post

Index of archived forum posts

Question:

Memory leak with OpenCertStore

Oct 03 '17 at 09:39

After many tests to locate what was causing memory problem in my servers, I located this memory leak .. when my program initialized the certificate, I noticed that much memory was allocated, and nothing was released

Basically, my C++ code to work with certs is:

class Certificate
{
private:
    CkCert* _certificate;

public:
    Certificate();
    ~Certificate();

    std::string sigMessage(std::string msg);

private:
    void loadCertificateFile(std::string pathCertificado, std::string senhaCertificado);
};

The implementation:

Certificate::Certificate()
    : _certificate(new CkCert())
{
}

Certificate::~Certificate()
{
    if (_certificate != nullptr)
        delete _certificate;
}

std::string Certificate::sigMessage(std::string msg)
{
    CkCrypt2* crypt = new CkCrypt2();
    bool success = crypt->UnlockComponent(CHILKAT_KEY_CRYPT);
    if (success != true)
        throw "";

    crypt->put_EncodingMode("Base64");
    crypt->SetSigningCert(*_certificate);

    CkString* ckStr = new CkString();
    crypt->OpaqueSignStringENC(msg.c_str(), *ckStr);
    std::string ret(ckStr->getStringAnsi());

    delete crypt;
    delete ckStr;

    return ret;
}

void Certificate::loadCertificateFile(std::string pathCertificado, std::string senhaCertificado)
{
    if (!_certificate->LoadPfxFile(pathCertificado.c_str(), senhaCertificado.c_str()))
        throw "";
}

Look at the image: https://imgur.com/a/41AFi

Memory leak detection


Answer

  1. Please read this: https://www.chilkatsoft.com/p/p_109.asp
  2. Make sure you're using the latest version of Chilkat

99.9% of all reported "memory leaks" are false, and are because the programmer does not understand the information presented at https://www.chilkatsoft.com/p/p_109.asp