small-tou / arduino-aliyun-iot-sdk

运行于 arduino 的 阿里云 IoT 接入 SDK,在底层连接的基础上增加数据回调绑定、发送数据和事件等 api 的封装,免去自己解析数据的痛苦
MIT License
8 stars 4 forks source link

new delete #18

Open yangminglong opened 3 years ago

yangminglong commented 3 years ago
boolean AliyunIoTSDK::publishUser(const char *topicSuffix, const char *payload){
    char topic[150]; 
    strcpy(topic, ALINK_TOPIC_USER);
    return AliyunIoTSDK::publish(strcat(topic, topicSuffix), payload);
}

boolean AliyunIoTSDK::subscribeUser(const char *topicSuffix, poniter_fun fp){
    char *topic = new char[150];
    strcpy(topic, ALINK_TOPIC_USER);
    return AliyunIoTSDK::subscribe(strcat(topic, topicSuffix), fp);
}

boolean AliyunIoTSDK::unsubscribeUser(char *topicSuffix){
    char *topic = new char[150];
    strcpy(topic, ALINK_TOPIC_USER);
    return AliyunIoTSDK::unsubscribe(strcat(topic, topicSuffix));
}

new 是否需要 delete

void AliyunIoTSDK::begin(Client &espClient,
                         const char *_productKey,
                         const char *_deviceName,
                         const char *_deviceSecret,
                         const char *_region)
{
    if (NULL != client)
        delete client;

    client = new PubSubClient(espClient);
...
}

网络重连时,重新调用begin() 是否需要 delete client

    if (NULL != client)
        delete client;