Menu

#1112 Memory leak in soap_set_namespaces

v1.0 (example)
closed-invalid
leak (1)
5
2017-03-28
2017-03-27
No

When there are two consecutive calls to the function soap_set_namespaces there is a memory leak of whatever is contained on soap->local_namespaces.

soap_set_namespaces(struct soap *soap, const struct Namespace *p)
{ struct Namespace *ns = soap->local_namespaces;
  struct soap_nlist *np, *nq, *nr;
  unsigned int level = soap->level;
  soap->namespaces = p;
  soap->local_namespaces = NULL;

soap->local_namespaces is set to NULL without freeing the memory allocated on the last call.
I think it is a good idea to free whatever is contained on the pointer before setting it to NULL.

Regards,
Juan

Discussion

  • Robert van Engelen

    You're forgetting that ns is set to the local_namespaces and this is later used to copy and delete the data in that same block of code:

      if (ns)
      { int i;
        for (i = 0; ns[i].id; i++)
        { if (ns[i].out)
          { SOAP_FREE(soap, ns[i].out);
            ns[i].out = NULL;
          }
        }
        SOAP_FREE(soap, ns);
      }
    
     
  • Robert van Engelen

    • status: open --> closed-invalid
     
  • Juan Fernández Ortiz

    Thank you for your fast response Robert.
    You are right, the leak is not there. I think it is on the "soap_copy_context" function.
    There you also have:

    copy->local_namespaces = NULL;
    

    But that address was not stored and it is not deleted (because the copy object could have something prior to the copy on local_namespaces).

    Anyways I am going to try to simplify what we did to reach this memory leak (shown by tcmalloc).
    We are using gSOAP 2.8.27.
    We create two NotificationServiceBindingService (lets call them "main" and "dup"), using the constructor

    NotificationServiceBindingService::NotificationServiceBindingService(soap_mode imode, soap_mode omode)
    

    and then we call

    soap_copy_context(dup->soap, main->soap)
    

    And after deleting both objects we have a leak on soap->local_namespaces of dup

    Leak of 1568 bytes in 7 objects allocated from:@  4d45ad soap_set_local_namespaces at stdsoap2_cpp.cpp:9840
    @  4d50d0 soap_set_namespaces at stdsoap2_cpp.cpp:9783
    @  4b1bb9 NotificationServiceBindingService::NotificationServiceBindingService_init(int, int) at soapNotificationServiceBindingService.cpp:64
    @  4b1af9 NotificationServiceBindingService::NotificationServiceBindingService(int, int) at soapNotificationServiceBindingService.cpp:43
    @  4374bd NotificationServiceProcess::NotificationServiceProcess() at NotificationServiceProcess.cc:306
    ...
    

    This leak doesn't show up if we manually free dup->soap->local_namespaces or if we call

    soap_free_temp(dup->soap);
    

    before the copy.

    Hope this make sense,
    Juan

     

Log in to post a comment.

MongoDB Logo MongoDB