Git Product home page Git Product logo

Comments (6)

wuhaogs avatar wuhaogs commented on July 20, 2024

是存在这个问题。mqtt_yield_thread线程创建时,调用platform_memory_alloc分配了96B,mqtt_yield_thread退出时,只是设置了分离线程,线程ID资源可以释放,但是platform_thread_t资源并未释放。我建议这样修复:linux版本中,platform_thread_destroy接口,释放mqtt_yield_thread线程管理资源。
void platform_thread_destroy(platform_thread_t* thread)
{
if (NULL != thread)
{
pthread_detach(thread->thread);
platform_memory_free(thread); //add
}
}

from mqttclient.

wuhaogs avatar wuhaogs commented on July 20, 2024

这样修复后,我发现还是存在问题,我正在尝试能否关闭重试逻辑。

from mqttclient.

wuhaogs avatar wuhaogs commented on July 20, 2024

一旦断网 mqtt_keep_alive接口中,调用network_release接口释放连接,此时n->socket无效,
所以并未调用network_disconnect释放连接,这样使得nettype_tls_params堆空间没有释放,并且此处复位了network_t n,这样n->channel变为0,
所以即使组件调用者主动断开连接,也无法释放此处空间。 目前删除下列memset 可以解决断网产生的内存泄漏
void network_release(network_t* n)
{
DBG_PRINT("[enter]network_release,n->socket=%d\n",n->socket);

if (n->socket >= 0)
    network_disconnect(n);

//memset(n, 0, sizeof(network_t)); //wuhaodel   LEAK MEM

}

from mqttclient.

henerywang avatar henerywang commented on July 20, 2024

void platform_thread_destroy(platform_thread_t* thread)
{
if (NULL != thread)
{
pthread_detach(thread->thread);
platform_memory_free(thread); //add
}
}
void network_release(network_t* n)
{
DBG_PRINT("[enter]network_release,n->socket=%d\n",n->socket);

if (n->socket >= 0)
network_disconnect(n);

//memset(n, 0, sizeof(network_t)); //wuhaodel LEAK MEM
}

这样修正后,问题还是存在,请帮忙再check check @wuhaogs

from mqttclient.

wuhaogs avatar wuhaogs commented on July 20, 2024

我目前通过注释源码中的重试机制,外部通过销毁客户端重建的方式进行重试。 通过virgrind内存检测,没发生泄漏问题。
// 1.注释源码中的重试流程
static int mqtt_try_reconnect(mqtt_client_t* c):
rc = mqtt_try_do_reconnect(c); -> rc = MQTT_NOT_CONNECT_ERROR;

// 2.调用者实现销毁mqtt客户端接口
int32 mbed_exitMqttClient()
{
MQTT_CLIENT_HANDLE clientID = (MQTT_CLIENT_HANDLE)getMqttClientHandle();

if (!clientID)
{
    return ERROR;
}

DBG_PRINT("[enter]exit MqttClient,state=%u\n", clientID->mqtt_client_state);


// 释放由调用mqtt_set_will_options产生的堆空间
if (clientID->mqtt_will_options)
{
    DBG_PRINT("[mqtt exit]mqtt_set_will_options(%p) free OK\n",clientID->mqtt_will_options);
    platform_memory_free(clientID->mqtt_will_options);
}

if (1 == clientID->mqtt_client_state || 2 == clientID->mqtt_client_state)
{
    DBG_PRINT("[mqtt exit]mqtt_disconnect\n");
    if (SUCCESS == mqtt_disconnect(clientID))
    {
        DBG_PRINT("[mqtt exit]mqtt_disconnect OK\n");
    }
    
    while (-1 != clientID->mqtt_client_state)
    {
        adlBlockWait(2, MILLISECOND);
    }
}

DBG_PRINT("[mqtt exit]mqtt_release,state =%d\n",clientID->mqtt_client_state);

if (SUCCESS == mqtt_release(clientID))
{
    DBG_PRINT("[mqtt exit]mqtt_release OK\n");
}

DBG_PRINT("[mqtt exit]call mqtt free(%p) OK\n", clientID);

platform_memory_free(clientID);

clientID = NULL;

setMqttClientHandle(NULL);

DBG_PRINT("[mqtt exit]destroy MqttClient\n\n");

return ETOK;

}

from mqttclient.

wuhaogs avatar wuhaogs commented on July 20, 2024

另外关于platform_thread_destroy内存泄漏问题,最新仓库中代码已经修复。

from mqttclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.