简体   繁体   English

Memory 泄漏使用 OpenSSL API

[英]Memory leak Using OpenSSL APIs

I am running a DTLS Server which handles more than 500 connections, every time some connections are closed i see there is some RAM memory utilization increases.我正在运行一个处理超过 500 个连接的 DTLS 服务器,每次关闭一些连接时,我都会看到一些 RAM memory 利用率增加。

I wonder there is a leak in memory from my below approach of Initialize_Sever_Context, create_connexion and close_connexion.我不知道 memory 中是否存在泄漏,原因是我的以下 Initialize_Sever_Context、create_connexion 和 close_connexion 方法。 The exact code is too big to create actual scenario, so i just outlined the step.确切的代码太大而无法创建实际场景,所以我只是概述了步骤。

Pls let me know if any extra information is required?如果需要任何额外信息,请告诉我?

I am using OpenSSL version 1.1.1k on Linux.我在 Linux 上使用 OpenSSL 版本 1.1.1k。

//connect_info structure user defined
{
 void* sll;
 void* bio;
 ....
}array_of_connections

*connect_info = &array_of_connections;
// global
SSL_CTX* server_ctx;

Initialize_Sever_Context()
{
    // server_ctx is global 
    server_ctx = SSL_CTX_new(DTLS_server_method());
    X509_VERIFY_PARAM *local_vpm = X509_VERIFY_PARAM_new()

    //setting verify flags, cookie flags and cypher lists etc..
    //....
    SSL_CTX_set1_param(server_ctx, local_vpm);
}

create_connexion(connect_info)
{
    // server_ctx is global
    ssl = SSL_new(server_ctx);
    
    bio = BIO_new_dgram(handler, BIO_NOCLOSE);
    ..
    ..
    SSL_set_bio(ssl, bio, bio);
    
    connect_info->ssl = ssl;
    connect_info->bio = bio;

}

handle_closed_connexions()
{
    for(conn = 1; conn<MAX_CONN;conn++)
    {
        close_connexion(connect_info[conn]);
    }
}

close_connexion(connect_info)
{
    // store prev ssl objects
    SLL *local_ssl = connect_info -> ssl;
    
    // make setup ready for the next connexions
    // and start listening
    create_connexion(connect_info)

    // free the previous closed connections
    SSL_free(local_ssl);
}

Inside SSL_free we have BIO_free_all(s->rbio), BIO_free_all(s->rbio) and BIO_CTX_free(s->ctx) and finally OPENSSL_free(s)在 SSL_free 中,我们有 BIO_free_all(s->rbio)、BIO_free_all(s->rbio) 和 BIO_CTX_free(s->ctx) 最后是 OPENSSL_free(s)

As far as i understand when we do SSL_free, all the members(pointers) inside SLL object are freed.据我所知,当我们执行 SSL_free 时,SLL object 中的所有成员(指针)都被释放了。 But inside OpenSSL non of pointers are set to NULL after free(), so i expect the application to crash.但是在 free() 之后,OpenSSL 中的非指针都设置为 NULL,所以我预计应用程序会崩溃。

But my application is working even after the pointers are freed.但即使在释放指针后我的应用程序仍在运行。

Why does not OpenSSL set the pointers to NULL after they are freed or Can i assume that my application is Safe with the above approach?为什么 OpenSSL 在释放后不将指针设置为 NULL 或者我可以假设我的应用程序使用上述方法是安全的吗?

I have checked posts 1 2 and others, but none of them satisfy my requirement, so i am asking a new question.我检查了帖子1 2和其他人,但没有一个满足我的要求,所以我问一个新问题。

Why does not OpenSSL set the pointers to NULL after they are freed or Can i assume that my application is Safe with the above approach?为什么 OpenSSL 在释放后不将指针设置为 NULL 或者我可以假设我的应用程序使用上述方法是安全的吗?

99.99% of the time, the pointers aren't going to be accessed again, so setting them to NULL serves no purpose. 99.99% 的时间,指针不会被再次访问,因此将它们设置为NULL没有任何意义。 If you do happen to need them set to NULL , then you can set them to NULL .如果您确实需要将它们设置为NULL ,那么您可以将它们设置为NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM