首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gsoap和资源管理

gsoap和资源管理
EN

Stack Overflow用户
提问于 2016-10-28 15:02:06
回答 1查看 140关注 0票数 0

我使用gsoap在我的C程序中实现了一些Web服务。

我像这样使用gsoap:

代码语言:javascript
复制
int motion_detector_check_status(const char *endpoint, 
        const motion_detector_subscription_result_t *sr, int *status) {
    int rc = EXIT_SUCCESS;
    double _timeout = difftime(sr->termination_time, sr->current_time);
    char timeout[TIMEOUT_MAX_LEN];
    struct soap *soap = soap_new();
    struct _tev__PullMessages request;
    struct _tev__PullMessagesResponse response;
    char *motion_state;

    if (!soap) return EXIT_FAILURE;

    snprintf(timeout, TIMEOUT_MAX_LEN, "PT%.0fS", _timeout < 5.0 ? _timeout : 5.0);

    request.MessageLimit = 1;
    request.Timeout = _timeout < 5.0 ? (int64_t)_timeout : 5.0;
    request.__any = timeout;
    request.__size = sizeof(timeout) + 1;

    rc = soap_call___tev__PullMessages(soap, endpoint, SOAP_ACTION_PULL_MESSAGE,
            &request, &response);

    if (rc != SOAP_OK) {
        soap_print_fault(soap, stderr);
        goto end;
    }

    if (response.wsnt__NotificationMessage && 
            response.wsnt__NotificationMessage->Topic &&
            response.wsnt__NotificationMessage->Topic->__any) {
        if (strstr(response.wsnt__NotificationMessage->Topic->__any, MOTION_ALARM_SRC)) {
            motion_state = strstr(response.wsnt__NotificationMessage->Message.__any,
                    "<tt:SimpleItem Name=\"State\" Value=");

            if (strcasestr(motion_state, "true"))
                *status = 1;
            else
                *status = 0;
        }
    }

    motion_detector_check_status_free_response(&response);
end:
    soap_end(soap);
    soap_destroy(soap);
    soap_free(soap);
    return rc;
}

所有操作都很好,但是struct _tev__PullMessagesResponse有一些指向char和其他结构的指针。

当我在valgring中运行我的程序时,它告诉我,我有内存泄漏,通过response中的指针引用的资源在motion_detector_check_status结束后是不空闲的。当然,我可以自己编写这个函数,但是我想知道gsoap提供函数来释放这些资源吗?

提前谢谢,为我的英语感到抱歉。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-22 15:30:55

嗯,深入研究soapcpp2,我发现选项-Ed女巫为gsoap使用的每一种类型生成soap_del_T宏。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40307886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档