Quantcast
Viewing all articles
Browse latest Browse all 1061

Memory leak with OpenCertStore

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

Image may be NSFW.
Clik here to view.
Memory leak detection


Viewing all articles
Browse latest Browse all 1061

Trending Articles