问题
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