ArhiChief ArhiChief - 10 months ago 70
C Question

gsoap and resource management

I use gsoap to implement some Web-service in my C program.

I use gsoap like this:

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;
*status = 0;

return rc;

Everything works well, but
struct _tev__PullMessagesResponse
has some pointers to char and other structures.

When I run my program in
it told me that I have memory leaks and resources referenced through pointers inside
aren't free after end of
. Of course I could write this functions by myself, but I'm wonder does gsoap provides functions to free this resources?

Thanks in advance, and sorry for my English.

Answer Source

Well, walking deeper throught docomentation to soapcpp2 I found option -Ed witch generates soap_del_T macros for each type used by gsoap.