473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

gSOAP server problem (memory leak)

I don't know if anybody here worked with gSOAP software, but I do hope so. I've made some simple server app using gSOAP example. Everythig worked fine until I switched it into ssl mode. Using it results in huge memory leak.

My question is if anybody has any idea what am I doing wrong or what am I missing?

Here is some of my code:
-----------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. #include "bmdsoap_server.h"
  2. #include "soapH.h"
  3. #include <signal.h>
  4. #include <stdio.h>
  5. #include <wchar.h>
  6. #include <bmd/libbmdpr/bmd_datagram/bmd_datagram_set.h>
  7. #include <bmd/libbmd/libbmd.h>
  8. #include <bmd/libbmdconfig/libbmdconfig.h>
  9. #include <bmd/libbmdts/libbmdts.h>
  10. //#include <conf_sections.h>
  11. #include <stdlib.h>
  12. #include <openssl/ssl.h>
  13. #include <openssl/x509.h>
  14. #include <openssl/ssl.h>
  15. #include <openssl/err.h>
  16. #include <openssl/bio.h>
  17.  
  18. #include <sys/types.h>
  19. #include <sys/wait.h>
  20.  
  21. void sigchld_handler(int id)
  22. {
  23.     int pid;
  24.     while ((pid = waitpid (-1, &id, WNOHANG)) > 0);
  25. }
  26.  
  27. void *server_function(void *soap)
  28. {
  29.  
  30.      if(soap_serve(soap)!=SOAP_OK)
  31.     {
  32.         printf("Error while serving client's request\n");
  33.         soap_print_fault(soap,stderr);
  34.         }
  35.     count++;
  36.     printf(" \tClient request served\n");
  37.  
  38.     soap_destroy((struct soap*)soap);
  39.       soap_end((struct soap*)soap);
  40.       soap_done((struct soap*)soap);
  41.       free(soap);
  42.  
  43.     return NULL;
  44. }
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.  
  49. int status=0;
  50. struct soap soap;
  51. struct soap *psoap=NULL;
  52. int m,s;
  53. pid_t pid=0;
  54.  
  55.     signal(SIGCHLD,sigchld_handler);
  56.  
  57.     system("clear");
  58.     printf("soap server puppy started\n");
  59.     soap_ssl_init();
  60.  
  61.     soap_init(&soap);
  62.     soap.bind_flags=SO_REUSEADDR;
  63.     soap.send_timeout = 10; // 60 seconds
  64.     soap.recv_timeout = 10; // 60 seconds
  65.     soap.max_keep_alive = 60; // max keep-alive sequence 
  66.  
  67.     if(soap_ssl_server_context(&soap,SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION," cert.pem","12345678",NULL,"cert_path",NULL,NULL,argv[0]))
  68.     {
  69.         printf("Error in setting encryption context\n");
  70.         soap_print_fault(&soap,stderr);
  71.         return -1;
  72.     }
  73.  
  74.     m=soap_bind(&soap,"127.0.0.1",9999,1000);
  75.     if(m<0)
  76.     {
  77.         printf("Error in binding socket\n");
  78.         soap_print_fault(&soap,stderr);
  79.         return -1;
  80.     }
  81.  
  82.     for(;;)
  83.     {
  84.         s = soap_accept(&soap);
  85.                 if(s<0)
  86.                 {
  87.             printf("Error in accepting connection\n");
  88.                         soap_print_fault(&soap,stderr);
  89.                         continue;
  90.                 }
  91.  
  92.         psoap=soap_copy(&soap);
  93.                 if(psoap==NULL)
  94.         {
  95.             printf("Error in duplication connection pointer\n");
  96.                     break;
  97.         }
  98.  
  99.         if(soap_ssl_accept(psoap))
  100.         {
  101.             printf("Error in ssl accepting connection\n");
  102.             soap_print_fault(&soap,stderr);
  103.             soap_end(psoap);
  104.             soap_done(psoap);
  105.             free(psoap);
  106.             //soap_free(psoap);
  107.             continue;
  108.         }
  109.         else
  110.         {
  111.             X509 *peer_cert=NULL;
  112.             peer_cert=SSL_get_peer_certificate(psoap->ssl);
  113.             if(peer_cert!=NULL)
  114.             {
  115.                 char issuer[256];
  116.                 char subject[256];
  117.                 X509_NAME_oneline(X509_get_issuer_name(peer_cert), issuer, 256);
  118.                 printf("Client certificate's issuer: %s\n",issuer);
  119.                 X509_NAME_oneline(X509_get_subject_name(peer_cert), subject, 256);
  120.                 printf("Client certificate's subject: %s\n",subject);
  121.             }
  122.             else
  123.             {
  124.                 printf("peer chujnia...\n");
  125.             }
  126.         }
  127.  
  128.         pid=fork();
  129.         if(pid==0)
  130.         {
  131.  
  132.             server_function((void *)psoap);
  133.             exit(0);
  134.         }
  135.         else
  136.         {
  137.             //soap_done(psoap);
  138.             free(psoap); psoap=NULL;
  139.             close(s);
  140.             /*czynności serwera :) */
  141.         }
  142.     }
  143.     return BMD_OK;
  144. }
  145.  
  146. int ns__testConnection(struct soap *soap, char **result)
  147. {
  148.     *result = (char*) soap_malloc(soap, 100);
  149.     sprintf(*result, "OK %i",1);
  150.     return SOAP_OK;
  151. }
-----------------------------------------------------------------------------------------------------

And here is what valgrind sais about emory leaks:
-----------------------------------------------------------------------------------------------------
92,971,064 (53,332 direct, 92,917,732 indirect) bytes in 199 blocks are definitely lost in loss record 5 of 10
==21641== at 0x40063C0: malloc (vg_replace_malloc.c:149)
==21641== by 0xBB9C5D: (within /lib/libcrypto.so.0.9.8b)
==21641== by 0xBBA2DE: CRYPTO_malloc (in /lib/libcrypto.so.0.9.8b)
==21641== by 0xCE8299: SSL_new (in /lib/libssl.so.0.9.8b)
==21641== by 0x80502D1: soap_ssl_accept (stdsoap2.c:3040)
==21641== by 0x804A863: main (bmdsoap_server.c:117)
==21641==
==21641==
==21641== 653,513 (23,296 direct, 630,217 indirect) bytes in 4 blocks are definitely lost in loss record 6 of 10
==21641== at 0x40063C0: malloc (vg_replace_malloc.c:149)
==21641== by 0x4BEA20C0: zcalloc (in /usr/lib/libz.so.1.2.3)
==21641== by 0x4BE9FB31: deflateInit2_ (in /usr/lib/libz.so.1.2.3)
==21641== by 0x4BE9FD61: deflateInit_ (in /usr/lib/libz.so.1.2.3)
==21641== by 0xC60927: (within /lib/libcrypto.so.0.9.8b)
==21641== by 0xC6055A: COMP_CTX_new (in /lib/libcrypto.so.0.9.8b)
==21641== by 0xCDCB6A: tls1_change_cipher_state (in /lib/libssl.so.0.9.8b)
==21641== by 0xCD0D65: ssl3_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCE60B9: SSL_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCD9CEC: ssl23_get_client_hello (in /lib/libssl.so.0.9.8b)
==21641== by 0xCDA52A: ssl23_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCE60B9: SSL_accept (in /lib/libssl.so.0.9.8b)
==21641==
==21641==
==21641== 2,659,453 bytes in 118 blocks are possibly lost in loss record 7 of 10
==21641== at 0x40063C0: malloc (vg_replace_malloc.c:149)
==21641== by 0xBB9C5D: (within /lib/libcrypto.so.0.9.8b)
==21641== by 0xBBA2DE: CRYPTO_malloc (in /lib/libcrypto.so.0.9.8b)
==21641== by 0xC6086A: (within /lib/libcrypto.so.0.9.8b)
==21641== by 0xC6055A: COMP_CTX_new (in /lib/libcrypto.so.0.9.8b)
==21641== by 0xCDCB6A: tls1_change_cipher_state (in /lib/libssl.so.0.9.8b)
==21641== by 0xCD0D65: ssl3_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCE60B9: SSL_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCD9CEC: ssl23_get_client_hello (in /lib/libssl.so.0.9.8b)
==21641== by 0xCDA52A: ssl23_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCE60B9: SSL_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0x80504FC: soap_ssl_accept (stdsoap2.c:3062)
==21641==
==21641==
==21641== 32,831,536 bytes in 530 blocks are possibly lost in loss record 9 of 10
==21641== at 0x40063C0: malloc (vg_replace_malloc.c:149)
==21641== by 0x4BEA20C0: zcalloc (in /usr/lib/libz.so.1.2.3)
==21641== by 0x4BEA2251: inflateInit2_ (in /usr/lib/libz.so.1.2.3)
==21641== by 0x4BEA2312: inflateInit_ (in /usr/lib/libz.so.1.2.3)
==21641== by 0xC608BC: (within /lib/libcrypto.so.0.9.8b)
==21641== by 0xC6055A: COMP_CTX_new (in /lib/libcrypto.so.0.9.8b)
==21641== by 0xCDCB6A: tls1_change_cipher_state (in /lib/libssl.so.0.9.8b)
==21641== by 0xCD0D65: ssl3_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCE60B9: SSL_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCD9CEC: ssl23_get_client_hello (in /lib/libssl.so.0.9.8b)
==21641== by 0xCDA52A: ssl23_accept (in /lib/libssl.so.0.9.8b)
==21641== by 0xCE60B9: SSL_accept (in /lib/libssl.so.0.9.8b)
==21641==
==21641== LEAK SUMMARY:
==21641== definitely lost: 76,628 bytes in 203 blocks.
==21641== indirectly lost: 93,547,949 bytes in 6,315 blocks.
==21641== possibly lost: 35,490,989 bytes in 648 blocks.
==21641== still reachable: 5,806,217 bytes in 36,061 blocks.
==21641== suppressed: 0 bytes in 0 blocks.
==21641== Reachable blocks (those to which a pointer was found) are not shown.
==21641== To see them, rerun with: --show-reachable=yes
-----------------------------------------------------------------------------------------------------

Please help my, because it blows my mind...

Regards.
Jan 15 '08 #1
1 13893
I just skimmed over the code. Don't the soap objects (in your case, 'psoap' in the main function, and 'soap' in server_function()) have a destructor? I think it's in the stdsoap2.cpp file.

In any case, I notice that you're freeing up the memory using soap_destroy(), soap_end(), and soap_done(). Essentially, you are doing what the destructor does. So, perhaps you can just do 'delete psoap;' instead.

Also, after you do that, you don't need to do 'free(psoap);'

Try that and write back if it works or not. Good luck.
Mar 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Eric Dennison | last post by:
I've been playing around with NuSOAP as a PHP based SOAP server and client. Works great! Now I'm trying to write (using gSOAP) a simple C/C++ based client to test against my simple SOAP server....
6
by: Ryan | last post by:
Hello, I am having trouble with a production db server that likes to gobble up memory. It seems to be a slow burn (maxing out over about an 18 hour time frame, before pegging both procs on the...
5
by: pete | last post by:
Can anyone give me some sugguestions here. Connection is declared at the start of the application Set rsFZReport.ActiveConnection = conn Then a function repeatly opens recordsets like this - ...
12
by: Bardolator | last post by:
I have a stand alone Java application that uses MS SQL Server 2000 and Microsoft JDBC ODBC drivers to access it. Before I run the application, I open the task Manager to monitor the memory used by...
2
by: liangrf | last post by:
My server app is transformed from environment of UNIX to Windows. Its ran on the Apache Windows Server. The code is compiled pass by MSVC6 and ran well. but it has more memory leak. when I am...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
5
by: ayaz.usman | last post by:
Hi, I've built a web services proxy server, in C# using wsdl.exe, by importing wsdl. Howeever, when I go to : http://localhost/sample.asmx?wsdl, they wsdl there does not match the wsdl I fed...
0
by: sumeta | last post by:
Hello Everyone , i m a fresher nd have to Develop TR-069 protocol (CPE WAN Management Protocol) using gSOAP toolkit , in c/c++ in Linux .. CPE WAN Management Protocol , intended for...
0
dav01it
by: dav01it | last post by:
Does someone have experience with gSoap and .NET webservices? I've build a .NET webservice that works very well but only with .NET clients. Creating a client with gsoap 7.10 gives errors: (...)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.