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
- #include "bmdsoap_server.h"
- #include "soapH.h"
- #include <signal.h>
- #include <stdio.h>
- #include <wchar.h>
- #include <bmd/libbmdpr/bmd_datagram/bmd_datagram_set.h>
- #include <bmd/libbmd/libbmd.h>
- #include <bmd/libbmdconfig/libbmdconfig.h>
- #include <bmd/libbmdts/libbmdts.h>
- //#include <conf_sections.h>
- #include <stdlib.h>
- #include <openssl/ssl.h>
- #include <openssl/x509.h>
- #include <openssl/ssl.h>
- #include <openssl/err.h>
- #include <openssl/bio.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- void sigchld_handler(int id)
- {
- int pid;
- while ((pid = waitpid (-1, &id, WNOHANG)) > 0);
- }
- void *server_function(void *soap)
- {
- if(soap_serve(soap)!=SOAP_OK)
- {
- printf("Error while serving client's request\n");
- soap_print_fault(soap,stderr);
- }
- count++;
- printf(" \tClient request served\n");
- soap_destroy((struct soap*)soap);
- soap_end((struct soap*)soap);
- soap_done((struct soap*)soap);
- free(soap);
- return NULL;
- }
- int main(int argc, char *argv[])
- {
- int status=0;
- struct soap soap;
- struct soap *psoap=NULL;
- int m,s;
- pid_t pid=0;
- signal(SIGCHLD,sigchld_handler);
- system("clear");
- printf("soap server puppy started\n");
- soap_ssl_init();
- soap_init(&soap);
- soap.bind_flags=SO_REUSEADDR;
- soap.send_timeout = 10; // 60 seconds
- soap.recv_timeout = 10; // 60 seconds
- soap.max_keep_alive = 60; // max keep-alive sequence
- if(soap_ssl_server_context(&soap,SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION," cert.pem","12345678",NULL,"cert_path",NULL,NULL,argv[0]))
- {
- printf("Error in setting encryption context\n");
- soap_print_fault(&soap,stderr);
- return -1;
- }
- m=soap_bind(&soap,"127.0.0.1",9999,1000);
- if(m<0)
- {
- printf("Error in binding socket\n");
- soap_print_fault(&soap,stderr);
- return -1;
- }
- for(;;)
- {
- s = soap_accept(&soap);
- if(s<0)
- {
- printf("Error in accepting connection\n");
- soap_print_fault(&soap,stderr);
- continue;
- }
- psoap=soap_copy(&soap);
- if(psoap==NULL)
- {
- printf("Error in duplication connection pointer\n");
- break;
- }
- if(soap_ssl_accept(psoap))
- {
- printf("Error in ssl accepting connection\n");
- soap_print_fault(&soap,stderr);
- soap_end(psoap);
- soap_done(psoap);
- free(psoap);
- //soap_free(psoap);
- continue;
- }
- else
- {
- X509 *peer_cert=NULL;
- peer_cert=SSL_get_peer_certificate(psoap->ssl);
- if(peer_cert!=NULL)
- {
- char issuer[256];
- char subject[256];
- X509_NAME_oneline(X509_get_issuer_name(peer_cert), issuer, 256);
- printf("Client certificate's issuer: %s\n",issuer);
- X509_NAME_oneline(X509_get_subject_name(peer_cert), subject, 256);
- printf("Client certificate's subject: %s\n",subject);
- }
- else
- {
- printf("peer chujnia...\n");
- }
- }
- pid=fork();
- if(pid==0)
- {
- server_function((void *)psoap);
- exit(0);
- }
- else
- {
- //soap_done(psoap);
- free(psoap); psoap=NULL;
- close(s);
- /*czynności serwera :) */
- }
- }
- return BMD_OK;
- }
- int ns__testConnection(struct soap *soap, char **result)
- {
- *result = (char*) soap_malloc(soap, 100);
- sprintf(*result, "OK %i",1);
- return SOAP_OK;
- }
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.