The XML streamers for OLW (OCL Light Weight) nodes in BoldOclLightWeightNodes.pas have memory leaks in their ReadObject methods. When deserializing from XML, CreateObject calls a constructor that allocates internal lists, then ReadObject overwrites the field pointer with the deserialized object — orphaning the constructor-allocated one.
Affected methods
| Streamer |
Leaked field |
Constructor that allocates it |
TBoldXMLOLWOperationStreamer.ReadObject |
fArgs (TBoldOLWNodeList) |
TBoldOLWOperation.Create |
TBoldXMLOLWMemberStreamer.ReadObject |
fQualifier (TBoldOLWNodeList) |
TBoldOLWMember.Create |
TBoldXMLOCLConditionStreamer.ReadObject |
fEnv (TBoldOLWNodeList) |
TBoldOclCondition.Create |
TBoldXMLOCLConditionStreamer.ReadObject |
fContext (TBoldObjectIdList) |
TBoldOclCondition.Create |
Impact
These streamers are invoked when OCL conditions are serialized/deserialized over XML, typically in distributed (SOAP) Bold persistence setups. Single-tier applications that evaluate OCL locally are not affected.
Each deserialization of an TBoldOclCondition leaks 4 objects (the NodeList, its internal TList, and for Context also TBoldObjectIdList + TBoldIntegerIndex).
Fix
Add FreeAndNil before each field assignment in ReadObject to free the constructor-allocated object before replacing it:
// Before (leaks):
OLWOperation.fArgs := Node.ReadSubNodeObject('Args', '') as TBoldOLWNodeList;
// After (fixed):
FreeAndNil(OLWOperation.fArgs);
OLWOperation.fArgs := Node.ReadSubNodeObject('Args', '') as TBoldOLWNodeList;
Same pattern for all 4 fields.
This is tested in class TTestBoldOLWNodeXMLStreaming
The XML streamers for OLW (OCL Light Weight) nodes in BoldOclLightWeightNodes.pas have memory leaks in their ReadObject methods. When deserializing from XML, CreateObject calls a constructor that allocates internal lists, then ReadObject overwrites the field pointer with the deserialized object — orphaning the constructor-allocated one.
Affected methods
TBoldXMLOLWOperationStreamer.ReadObjectfArgs(TBoldOLWNodeList)TBoldOLWOperation.CreateTBoldXMLOLWMemberStreamer.ReadObjectfQualifier(TBoldOLWNodeList)TBoldOLWMember.CreateTBoldXMLOCLConditionStreamer.ReadObjectfEnv(TBoldOLWNodeList)TBoldOclCondition.CreateTBoldXMLOCLConditionStreamer.ReadObjectfContext(TBoldObjectIdList)TBoldOclCondition.CreateImpact
These streamers are invoked when OCL conditions are serialized/deserialized over XML, typically in distributed (SOAP) Bold persistence setups. Single-tier applications that evaluate OCL locally are not affected.
Each deserialization of an TBoldOclCondition leaks 4 objects (the NodeList, its internal TList, and for Context also TBoldObjectIdList + TBoldIntegerIndex).
Fix
Add FreeAndNil before each field assignment in ReadObject to free the constructor-allocated object before replacing it:
// Before (leaks):
// After (fixed):
Same pattern for all 4 fields.
This is tested in class TTestBoldOLWNodeXMLStreaming