Menu

#4 Memory leaks with TSAXContentHandler

open
None
5
2005-04-11
2004-10-01
No

Hi

When I prepare a SAX Parser like

function TLDDocument.PrepareParse:IBaseXMLReader;
var
vendor: TSAXVendor;
contentHandler: TSAXContentHandler;
errorHandler: TSAXErrorHandler;
begin
// error handling
errorHandler := TSAXErrorHandler.Create(nil);
errorHandler.OnWarning := DoLogWarning;
errorHandler.OnError := DoLogError;
errorHandler.OnFatalError := DoLogError;
// Content handling
contentHandler := TSAXContentHandler.Create(nil);
contentHandler.OnSetDocumentLocator :=
DoSetDocumentLocator;
contentHandler.OnStartElement := DoStartElement;
contentHandler.OnEndElement := DoEndElement;
contentHandler.OnCharacters := DoCharacters;
// Get the SAX Parser
vendor := GetSAXVendor(SAX_VENDOR);
if vendor is TBufferedSAXVendor then begin
result := TBufferedSAXVendor(vendor).BufferedXMLReader;

IBufferedXMLReader(result).setContentHandler(Adapt(contentHandler,
IBufferedXMLReader(result)));
end else begin
result := vendor.XMLReader;
IXMLReader(result).setContentHandler(contentHandler);
end;
result.setErrorHandler(errorHandler);
end;

Then I get MemoryLeaks because the errorHandler and the
contentHandler are not freed. The refcount is alway 2
at the end instead of 0. I found out, that in the unit
SAXComps.pas in
TSAXInterfacedComponent.AfterConstruction the Refcount
is incremented (_AddRef;) instead of decremented
(InterlockedDecrement(FRefCount);)

In our project this change fixes the memory leaks and
has no other side effects:

procedure TSAXInterfacedComponent.AfterConstruction;
begin
inherited;
FOwnerIsComponent:= (Owner <> nil) and (Owner is
TComponent);
// _AddRef; removed by Sowatec
InterlockedDecrement(FRefCount); // inserted by
Sowatec (Memory leak)
end;

Can you confirm this bug?

Regards

Michael Kleidt

Discussion

  • Karl Waclawek

    Karl Waclawek - 2005-04-11
    • assigned_to: nobody --> jeffrafter
     
  • Karl Waclawek

    Karl Waclawek - 2005-04-11

    Logged In: YES
    user_id=290026

    It seems we never got notified of this bug entry.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.