2016-10-28 27 views
0

我在我的C程序中使用gsoap来实现一些Web服务。gsoap和资源管理

我用gSOAP的是这样的:

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上运行我的程序时,它告诉我存在内存泄漏,并且在motion_detector_check_status结束后通过response内指针引用的资源不是免费的。当然我可以自己写这个函数,但是我想知道gsoap是否提供了释放这些资源的函数?

在此先感谢,并为我的英语感到遗憾。

回答

0

那么,走深的通过docomentation到soapcpp2我发现选项-Ed女巫生成soap_del_T宏由gsoap使用的每种类型。