You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Catalina Caloian <Ca...@quintiq.com> on 2009/03/05 10:09:43 UTC

Memory leak in deserialize method

Hello

The following snippet taken from a generated deserialize method may lead to a memory leak:

axutil_hash_index_t *hi;
for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) 
 {
        axutil_hash_this(hi, &key, NULL, &val);                           
         if(!strcmp((axis2_char_t*)key, "someName"))
         {
               parent_attri = (axiom_attribute_t*)val;
               break;
          }
 }

hi gets allocated in axutil_hash_first.
hi is freed in axutil_hash_next, but only when the end of the hash array has been reached. However, in the code above, we exit the for loop when we find the desired hash entry. In such a case, axutil_hash_next never gets to the and of the hash array and thus hi is never freed.

A possible fix might be to change the CADBBeanTemplateSource.xsl so that the generated code looks something like this:

axutil_hash_index_t *hi;
for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) 
 {
        axutil_hash_this(hi, &key, NULL, &val);                           
         if(!strcmp((axis2_char_t*)key, "someName"))
         {
               parent_attri = (axiom_attribute_t*)val;
               // added from here
               AXIS2_FREE(env->allocator, hi);
               // added up to here
               break;
          }
 }





Catalina-Georgiana Caloian
Software Engineer
 
Quintiq
 
T +31 (0) 73 691 07 39
F +31 (0) 73 691 07 54
M +31 (0) 65 247 63 99
E catalina.caloian@quintiq.com
I www.quintiq.com



This message contains information that may be privileged or confidential and is the property of Quintiq. It is only intended for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute or use this message or any part thereof. If you have received this message in error, please notify the sender immediately and delete all copies of this message. Please note that e-mails are susceptible to change, therefore they are not binding.