gsoap response memory allocation nested structure

杀马特。学长 韩版系。学妹 提交于 2020-03-25 21:51:47

问题


Im trying to find the right way of allocation memory for the following structure.

struct part1 {
      char* c1;
      char* c2;
}
struct part2 {
    int a;
    struct part1 *local;
}

struct response {
      struct part1* p1;
      struct part2* p2;
}

This is what I do, as gathered from the documents.

int myservice ( soap *soap, struct request *request, struct response *resp) { ... // top level resp is setup by soap_serve

resp->p1 = soap_new_ns__part1(soap,1);
resp->p1->c1 = soap_new_string(soap,10); (also tried soap_malloc(soap,10))
resp->p1->c2 = soap_new_string(soap,10);
strcpy(resp->p1->c1, “first”)
strcpy(resp->p1->c2, “second”)

resp->p2 = soap_new_ns__part2(soap,1);
resp->p2->a = 123;
resp->p2->local = soap_new_ns__part1(soap,1);
resp->p2->  c1 and c1 as above
etc...

But this seems to end in memory leak; although I call the soap_destroy, soap_end. I am using the process_queue example for the server implementation.

Is there an obvious problem that I am not seeing ?

Thanks.

来源:https://stackoverflow.com/questions/58941581/gsoap-response-memory-allocation-nested-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!