2016-10-28 12 views
0

gsoapを使用して、Cプログラムで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

よく聞くと、soapcpp2への詳細な説明があります。-Edの魔女は、gsoapで使用されるタイプごとにsoap_del_Tマクロを生成します。

関連する問題