Menu

#1368 cacertinmem.c sample memory leak

closed-fixed
None
5
2014-08-19
2014-05-08
Marko
No

While investigating a memory leak in our application, I discovered that "sslctx_function" callback that was implemented following the cacertinmem.c sample was causing it.

After X509_STORE_add_cert, X509_free(cert) should be called, as X509_STORE_add_cert increments reference count. Also, BIO_free(bio) must be called.

Discussion

  • Daniel Stenberg

    Daniel Stenberg - 2014-05-08

    Thanks! Any chance you can provide a patch for your suggested fix?

     
  • Daniel Stenberg

    Daniel Stenberg - 2014-05-08
    • assigned_to: Daniel Stenberg
     
    • Marko

      Marko - 2014-05-09

      Of course. Attached is a modified sample, search for text "LEAKFIX".

      How to debug:
      - cert->references is 1 before call to X509_STORE_add_cert, and 2 after a
      call. So we need to call X509_free(cert) to decrease the cert->reference
      back to 1 (referenced from X509 store).
      - BIO_new_mem_buf returns new "bio" stream, BIO_free call is missing. BIO
      objects are also reference counted, so BIO_free decreases the count to 0
      and deletes the object.

      Regards,
      Marko

       

      Last edit: Daniel Stenberg 2014-05-09
  • Daniel Stenberg

    Daniel Stenberg - 2014-05-09

    Did you forget to attach the fixed example?

     
  • Marko

    Marko - 2014-05-09

    Sorry, I replied to a mail and it seems that attachments were removed by mailing list.

     
  • Daniel Stenberg

    Daniel Stenberg - 2014-05-09
    • status: open --> closed-fixed
     
  • Daniel Stenberg

    Daniel Stenberg - 2014-05-09

    Execellent and thanks a lot! The fix has been committed and pushed. Case closed!