Remo Inverardi <[EMAIL PROTECTED]>:

> With OpenSSL 0.9.4, Visual C++ reports memory leaks even if I only
> use these two lines of OpenSSL code:

>> SSL_CTX *ctx = SSL_CTX_new(SSLv2_server_method());
>> SSL_CTX_free(ctx);

> Question is: do I have to free anything else manually or is the
> leak caused by a OpenSSL "bug".

At the end of a program, always delete OpenSSL's per-thread error
queue by calling ERR_remove_state(0) (0 means the current thread).
Under Windows, if you use multiple threads, each thread that exits
will automatically have its error queue deleted, but presumably your
memory-leak checking takes place before the main thread has exited.

The reason that you get an error message from SSL_CTX_new (and ctx ==
NULL) in your example is that you did not load the algorithms by
calling SSLeay_add_ssl_algorithms(). (You probably also want to load
the error strings so that you won't have to decipher numerical OpenSSL
error codes manually: call ERR_load_crypto_strings() and
SSL_load_error_strings()).  Before the program exits, call
EVP_cleanup() and ERR_free_strings() to free the memory allocated in
these steps.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to