gsoap会在我打电话的第二次时段中删除我的应用程序(用C语言编写)

时间:2013-12-18 19:16:25

标签: c++ c web-services soap struct

我的gsoap Client Caller在soap_call___ns4__QueryAccBalIO的每次第二次调用中都会被隔离。根据gsoap的文档,我通过soap_malloc分配内存并使用soap_end释放它,并且在下面的每个循环之后调用soap_free也是我在客户端调用者中使用的一段代码。

struct soap *soap = soap_new();

/**** Declaration of Client Structures ****/

struct _ns1__QUERYACCBAL_USCOREIOFS_USCOREREQ *QueryBal;
struct _ns1__QUERYACCBAL_USCOREIOFS_USCORERES *QueryRes;
struct _ns2__CREATETRANSACTION_USCOREIOPK_USCOREREQ *CreateTran;
struct _ns2__CREATETRANSACTION_USCOREIOPK_USCORERES *ResTran;
struct _ns2__REVERSETRANSACTION_USCOREIOPK_USCOREREQ *ReverseTran;
struct _ns2__REVERSETRANSACTION_USCOREIOPK_USCORERES *RevResTran;


if (!soap)
{
 printf ("Exiting Thread.......");
 return (void*) 0;
}


/**** Allocation ****/

QueryBal = (struct _ns1__QUERYACCBAL_USCOREIOFS_USCOREREQ *)soap_malloc(soap,sizeof(struct _ns1__QUERYACCBAL_USCOREIOFS_USCOREREQ));
QueryBal->FCUBS_USCOREHEADER=(struct ns1__FCUBS_USCOREHEADERType *)soap_malloc(soap,sizeof(struct ns1__FCUBS_USCOREHEADERType));
QueryBal->FCUBS_USCOREBODY.ACC_Balance=(struct ns1__Acc_Bal_Req_type *)soap_malloc(soap,sizeof(struct ns1__Acc_Bal_Req_type));
QueryRes = (struct _ns1__QUERYACCBAL_USCOREIOFS_USCORERES *)soap_malloc(soap,sizeof(struct _ns1__QUERYACCBAL_USCOREIOFS_USCORERES));

/**** Section of Assignment *****/

/**** Just right after Assignment Section gsoap Client Call ****/

rc = soap_call___ns4__QueryAccBalIO(soap,ReqResElements[a2->WS_ID].ConnectionString, NULL, QueryBal, QueryRes);

/**** Section Where soap_end() and soap_free() is being called *****/

if (rc)
{
    // SOAP REQUEST REJECTED :(

    printf("SOAP Request Rejected :( ");

        soap_end(soap);

    soap_free(soap);

    printf("Exiting Thread.....");

    return (void *) 0;

}

soap_end(soap);
soap_free(soap);

现在根据我的理解它应该可以正常工作,但是当我的客户端调用者第一次调用soap_call___ns4__QueryAccBalIO时它会获得成功结果。但是第二次当我的客户端调用者调用相同的函数时,它会被分割出来。

当我从代码中删除soap_end(soap)和soap_free(soap)时,它不会出现段错误,但是,不要调用soap_end和soap_free它可能会遇到内存泄漏问题。

1 个答案:

答案 0 :(得分:0)

肯定像valgrind这样的记忆检查器可以帮助你。

我在代码中感到奇怪的是使用soap_malloc来分配请求/响应参数。

你有没有尝试过:

_ns1__QUERYACCBAL_USCOREIOFS_USCOREREQ QueryBal;
QueryBal.FCUBS_USCOREHEADER=(struct ns1__FCUBS_USCOREHEADERType *)soap_malloc(soap,sizeof(struct ns1__FCUBS_USCOREHEADERType));
QueryBal.FCUBS_USCOREBODY.ACC_Balance=(struct ns1__Acc_Bal_Req_type *)soap_malloc(soap,sizeof(struct ns1__Acc_Bal_Req_type));
_ns1__QUERYACCBAL_USCOREIOFS_USCORERES QueryRes;
...
rc = soap_call___ns4__QueryAccBalIO(soap,ReqResElements[a2->WS_ID].ConnectionString, NULL, &QueryBal, &QueryRes);