0

I am using openssl in my project. When I exit my application I get "Detected memory leaks!" in Visual Studio 2013.

Detected memory leaks!
Dumping objects ->
{70202} normal block at 0x056CB738, 12 bytes long.
 Data: <8 j         > 38 E8 6A 05 00 00 00 00 04 00 00 00 
{70201} normal block at 0x056CB6E8, 16 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{70200} normal block at 0x056CB698, 20 bytes long.
 Data: <      l         > 00 00 00 00 E8 B6 6C 05 00 00 00 00 04 00 00 00 
{70199} normal block at 0x056AE838, 12 bytes long.
 Data: <      l     > 04 00 00 00 98 B6 6C 05 00 00 00 00 
{70198} normal block at 0x056CB618, 64 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{70197} normal block at 0x056CB578, 96 bytes long.
 Data: <  l    3   3    > 18 B6 6C 05 00 FE C0 33 C0 FD C0 33 08 00 00 00 
Object dump complete.

When I add

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetBreakAlloc(70202);

to main main function I always get a breakpoint at the allocation of the x509 store, no matter for which of the 6 numbers (70202,...) I set the break point.

I initialize and uninitialize the x509 store in a class' constructor and destructor (see below). Is there anything else I need to look out for when using the x509_STORE?

Foo::CSCACerts::CSCACerts(void)
{
    m_store = X509_STORE_new();
}


Foo::CSCACerts::~CSCACerts(void)
{
    X509_STORE_free( m_store );
}
jww
  • 97,681
  • 90
  • 411
  • 885
tzippy
  • 6,458
  • 30
  • 82
  • 151
  • `and deconstructor` -- The term is *destructor*, not *deconstructor*. Second, memory leaks can be caused due to the instance of the class itself (`Foo::CSACerts`) is not deallocated. – PaulMcKenzie Jul 08 '16 at 10:52
  • @PaulMcKenzie thanks, I corrected that. – tzippy Jul 08 '16 at 10:59
  • You never stated whether the destructor is actually called. Is the destructor called? – PaulMcKenzie Jul 08 '16 at 11:07
  • Forgot to mention that. Yes, there's one instance created of ´CSCACerts´ and its destructor is called. – tzippy Jul 08 '16 at 11:09
  • 1
    You need to post a [mcve], or at the very least, write a very simple `main()` program that only calls the `X509_STORE_new` and `X509_Store_free` function and ensure that this does not have memory leaks. Introducing classes into the mix only can cloud the issue -- we don't know if copies are being made of your object, and there is a copy that you're not aware of. – PaulMcKenzie Jul 08 '16 at 11:15
  • OpenSSL leaks memory like a sieve. The problem is some of the OpenSSL devs feel cleanup is *not* necessary. That appears to be changing at 1.1.0, however. Also see [OpenSSL *possible* memory leak](http://stackoverflow.com/q/21532371), [How to properly uninitialize OpenSSL](http://stackoverflow.com/q/29845527), [OpenSSL::SSL_library_init() memory leak](http://stackoverflow.com/q/11759725), [Memory leak in OpenSSL function EVP_EncryptFinal_ex](http://stackoverflow.com/q/18503993), ... – jww Jul 10 '16 at 02:02
  • Also see [Memory leaks reported by debug CRT inside typeinfo.name()](https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=106937) on Microsoft Connect. That issue has been around for at least a decade, dating back to the VC++ 4.0 days... – jww Jul 10 '16 at 03:27

0 Answers0