Skip to content

Memory leaks in OLW XML streamer ReadObject methods #34

@bero

Description

@bero

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions