Memory leak in cpxml.clw

I submitted this in the PTSS a while back but it has only progressed to “Opened for Review”. See PTSS#40365 I notice that it is not fixed in the latest C9.1 I have installed and I am assuming the same is true for C10 though I have not actually checked yet.

Description:
The toDOM:AppendCol procedure is no releasing newly created nodes when style=DOMStyle:ADO_Net
XMLExchange.AddRow calls this procedure a fair bit so memory usage can grow a fair bit.

Steps to Reproduce:
I found it when calling GroupToDOM. It only occurs when style=DOMStyle:ADO_Net

For example this line:

colE.appendChild(doc.createTextNode(cs.str(clip(sw.getFieldValueByIndex(col)))))
Should be:

T &= doc.createTextNode(cs.str(clip(sw.getFieldValueByIndex(col))))
if NOT T &= NULL
colE.appendChild(T)
T.Release()
end

Here is the fixed version of toDOM:AppendCol that I am using now:

toDOM:AppendCol procedure(*XMLExchange exch, *Document doc, *Element rowE, StructWrapper sw, signed col, DOMStyle style)

colE      &Element, auto
colA      &Attr, auto
cs        CStringClass
value     CStringClass
fldFormat XMLFieldFormat
tp        UNSIGNED  
T &Text, auto
CData &CDATASection
  code
  tp=sw.getFieldType(col)
  if style = DOMStyle:ADO_26 then
    !Attribute-based style    
    !Add attribute to the DOM
    if sw.getXMLFieldFormatByIndex(col, fldFormat) = CPXMLErr:NoError then
      if fldFormat = XMLFieldFormat:CData
        return CPXMLErr:CDataNotSupported
      elsif fldFormat = XMLFieldFormat:Base64 
        return CPXMLErr:Base64NotSupported
      end
    end
    colA &= doc.createAttribute(cs.str(sw.getXMLFieldLabel(col)))  !was lower(tag) [MAL]
    rowE.setAttributeNode(colA)
    colA.setValue(cs.str(clip(sw.getFieldValueByIndex(col))))
    colA.release()
  elsif style = DOMStyle:ADO_Net then
    !tag-based style
    !Add new element to the DOM corresponding to column
    colE &= doc.createElement(cs.str(sw.getXMLFieldLabel(col))) !was lower(tag) [MAL]
    rowE.appendChild(colE)
    if sw.getXMLFieldFormatByIndex(col, fldFormat) <> CPXMLErr:NoError then      
      T &= doc.createTextNode(cs.str(clip(sw.getFieldValueByIndex(col))))
      if NOT T &= NULL
        colE.appendChild(T)
        T.Release()
      end
    else
      ! test field format
      if fldFormat = XMLFieldFormat:CData then
        CData &= doc.createCDATASection(cs.str(clip(sw.getFieldValueByIndex(col))))
        if NOT CData &= NULL
          colE.appendChild(T)
          CData.Release()
        end
      elsif fldFormat = XMLFieldFormat:Base64 then
        exch.setNamespace()
        colE.setAttribute(e:XsiType, e:Base64)
        value.str(clip(sw.getFieldValueByIndex(col)))
        cs.str(tobase64(value.str()))
        T &= doc.createTextNode(cs.str())
        if NOT T &= NULL
          colE.appendChild(T)
          T.Release()
        end
      else        
        !usual case 
        T &= doc.createTextNode(cs.str(clip(sw.getFieldValueByIndex(col))))
        if NOT T &= NULL
          colE.appendChild(T)
          T.Release()
        end
      end
    end
    colE.release()
  else
    assert(false, '<13,10>Unknown DOMStyle:  ' & style)
  end
  return 0