Dear sirs.

I'm learning about gsoap and I built a quite dumb test server and client.

In order to test its speed, the client makes 100000 queries to the
server and I noticed that both client and server leak memory (the client
noticeably leaks more than the server). However they have not any
dynamic memory allocated.

It is built and linked against gSoap-2.7.17 and the source code follows

========BEGIN SERVER SOURCE=========
#include <string.h>
#include "SOAP_H.h"
#include "sample.nsmap"

static void soap_server_loop() {
    int m, s, i; // master and slave sockets
    struct soap mysoap;
    soap_init(&mysoap);
    m = soap_bind(&mysoap, NULL, 8080, 100);
    if (m < 0) {
        soap_print_fault(&mysoap, stderr);
    } else {
        printf("Socket connection successful: master socket = %d\n", m);
        for (i = 1; ; i++) {
             s = soap_accept(&mysoap);
            if (s < 0) {
                soap_print_fault(&mysoap, stderr);
                break;
            }
            if (soap_serve(&mysoap) != SOAP_OK) // process RPC request
                soap_print_fault(&mysoap, stderr); // print error
            soap_destroy(&mysoap); // clean up class instances
            soap_end(&mysoap); // clean up everything and close socket
        }
    }
    soap_done(&mysoap); // close master socket and detach environment
}

SOAP_FMAC5 int SOAP_FMAC6 ns1__queryTest(struct soap* sp, struct
ns1__queryteststruct *querydata, struct ns1__queryTestRsponse *response) {
    static char buffer[1000];
    strcpy(buffer, "Response to ");
    strncat(buffer, querydata->teststring, 999);
    response->teststruct.testinteger = querydata->testinteger * 2;
    response->teststruct.teststring = buffer;
    response->retval = 0;
    return 0;
}

int main() {
    soap_server_loop();
    return 0;
}
========END SERVER SOURCE=========

========BEGIN CLIENT SOURCE=========
#include <stdio.h>
#include <string.h>
#include "sample.nsmap"
#include "SOAP_H.h"
#include "stdsoap2.h"


#define SERVER_URL "http://localhost:8080";


int main() {
    int i, retvalsoap;
    struct soap mysoap;
    char buffer[1000];
    ns1__queryteststruct myquery;
    ns1__queryTestRsponse myresponse;
    myquery.teststring = buffer;
    soap_init(&mysoap);
    for(i = 0; i < 100000; i++) {
        myquery.testinteger = i;
        sprintf(myquery.teststring, "query number %d", i);
        retvalsoap = soap_call_ns1__queryTest(&mysoap, SERVER_URL, NULL,
&myquery, &myresponse);
    }
    soap_destroy(&mysoap); // clean up class instances
    soap_end(&mysoap); // clean up everything and close socket
    soap_done(&mysoap); // close master socket and detach environment
    return 0;
}
========END CLIENT SOURCE=========

Just for reference, bellow is the file "sample_SOAP.h" which was the
input to "soapcpp2 -c -s -w -x -pSOAP_ sample_SOAP.h":

========BEGIN HEADER=========
//gsoap ns1   schema namespace:   
http://www.fensomsystem.com/wsdl/soaptest.wsdl
//gsoap ns1   schema form:    unqualified

typedef char* ns1__string1000    0:1000;

typedef struct ns1__queryteststruct {
    int                        testinteger    1;
    ns1__string1000            teststring    1;
} ns1__queryteststruct;



//gsoap ns1  service name:    sample
//gsoap ns1  service type:    sample_PortType
//gsoap ns1  service port:    http://localhost:8080
//gsoap ns1  service namespace:    urn:fs:sample
//gsoap ns1  service transport:    http://schemas.xmlsoap.org/soap/http



typedef struct ns1__queryTestRsponse {
    int                        retval        1;
    ns1__queryteststruct    teststruct    1;
} ns1__queryTestRsponse;
//gsoap ns1  service method-style:    queryTest rpc
//gsoap ns1  service method-action:    queryTest queryTest
int ns1__queryTest(ns1__queryteststruct* querydata,
ns1__queryTestRsponse* response);
========END HEADER=========

Because all (including gSOAP) is built with DEBUG symbol defined, both
server and client have created a TEST.log each, I analyzed the client's
one and I noticed that just below each line that contains "Begin send
phase..." there is a line "stdsoap2.c(6789): malloc(32) = x" where x is
a hexadecimal number (the pointer returned, I guess).
In this log file, none of these mallocs have a corresponfing free(x) but
other mallocs in log file have.

I just begun to analyze the server log but I can't found any malloc
without free.

Is this a gSoap bug or am I doing something wrong?

Thank you in advance.

Best regards.

Francisco J. Lazur

Reply via email to