[ 
https://issues.apache.org/jira/browse/AXIS2C-1609?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Robert Lazarski resolved AXIS2C-1609.
-------------------------------------
    Fix Version/s: 2.0.0
                       (was: 1.7.0)
       Resolution: Fixed

 When iterating over a hash table with axutil_hash_first/axutil_hash_next,
    the iterator is allocated on the heap. This memory is automatically freed
    when axutil_hash_next reaches the end of iteration and returns NULL.
    
    However, if code breaks out of the iteration loop early (e.g., after
    finding a specific key), the iterator memory leaks because axutil_hash_next
    never gets to free it.
    
    This fix adds a new function axutil_hash_index_free() that callers can use
    to properly clean up the iterator when breaking out of a loop early:
    
        for (hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, 
hi)) {
            axutil_hash_this(hi, &key, NULL, &val);
            if (found_what_we_need) {
                axutil_hash_index_free(hi, env);  /* AXIS2C-1609: Clean up 
iterator */
                break;
            }
        }


> memory leak in axutil_hash_first() / axutil_hash_next() in generated xml 
> deserializer code for an xsd element with attributes
> -----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AXIS2C-1609
>                 URL: https://issues.apache.org/jira/browse/AXIS2C-1609
>             Project: Axis2-C
>          Issue Type: Bug
>          Components: code generation, util
>    Affects Versions: 1.7.0
>         Environment: probably all (noticed on iOS with Xcode memory leak 
> detector)
>            Reporter: Jürgen Keil
>            Priority: Major
>             Fix For: 2.0.0
>
>
> In the generated adb_{type}_deserialize() code ( 
> adb_ActiveOrHistoricCurrencyAndAmount_deserialize() 
> in my case), code like this can be found:
> ...
>                   parent_attri = NULL;
>                   attrib_text = NULL;
>                   if(attribute_hash)
>                   {
>                        axutil_hash_index_t *hi;
>                        void *val;
>                        const void *key;
>                        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, "Ccy"))
>                              
>                                {
>                                    parent_attri = (axiom_attribute_t*)val;
>                                    break;
>                                }
>                        }
>                   }
>                   if(parent_attri)
>                   {
>                     attrib_text = axiom_attribute_get_value(parent_attri, 
> env);
>                   }
>                   else
>                   {
>                     /* this is hoping that attribute is stored in "Ccy", this 
> happnes when name is in default namespace */
>                     attrib_text = 
> axiom_element_get_attribute_value_by_name(parent_element, env, "Ccy");
>                   }
> ...
> axutil_hash_first() allocates some memory (when env != NULL), which is freed 
> by
> axutil_hash_next() when we reach the end of the hash list.
> But when we do find the correct key before reaching the end of the list 
> ("Ccy" in the
> above case), we break out of the for loop and axutil_hash_next() will never 
> reach the
> end of the list so that the allocated "hi" hash iterator never gets freed.
> (Partial) XSD to reproduce the issue (xml element with attribute);
>         <xs:complexType name="ActiveOrHistoricCurrencyAndAmount">
>                 <xs:simpleContent>
>                         <xs:extension 
> base="ActiveOrHistoricCurrencyAndAmount_SimpleType">
>                                 <xs:attribute name="Ccy" 
> type="ActiveOrHistoricCurrencyCode" use="required"/>
>                         </xs:extension>
>                 </xs:simpleContent>
>         </xs:complexType>
>         <xs:simpleType name="ActiveOrHistoricCurrencyAndAmount_SimpleType">
>                 <xs:restriction base="xs:decimal">
>                         <xs:minInclusive value="0"/>
>                         <xs:fractionDigits value="5"/>
>                         <xs:totalDigits value="18"/>
>                 </xs:restriction>
>         </xs:simpleType>
>         <xs:simpleType name="ActiveOrHistoricCurrencyCode">
>                 <xs:restriction base="xs:string">
>                         <xs:pattern value="[A-Z]{3,3}"/>
>                 </xs:restriction>
>         </xs:simpleType>



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to