473,223 Members | 1,727 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,223 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 13818
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: (...)...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...

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.