Segmentation fault in Message destructor when using stack memory

19 views
Skip to first unread message

Andrew Michell

unread,
Aug 15, 2024, 3:08:17 PM8/15/24
to fix8 support
Hi Fix8 Support,

I am attempting to use stack memory for my messages and fields however FIX8::MessageBase's destructor calls clear(false) which uses the 'delete' operator on all entries in the _fields map.  This results in a seg fault since the fields are not heap allocated.

I don't see any way to remove fields from the map, or clear the map without the use of 'delete'.

Here is some pseudo code that illustrates the issue:

struct MyMessageWithFields
{
    // Actual FIX8 message
    FIX8::MyFix::MyMessage msg{};

    // Fields
    FIX8::MyFix::Field1 field1{};
    FIX8::MyFix::Field2 field2{};

    MyMessageWithFields() {
        msg.add_field(&field1);
        msg.add_field(&field2);
    }

    ~MyMessageWithFields() {
        // Would be nice to remove fields here
    }
};

int main(int argc, char *argv[])
{
    {
        MyMessageWithFields myMessage{};
    } // seg fault here

    return 0;
}


Please advise on how to use stack memory for fields without running into this seg fault.

Thanks,
Andrew Michell

Andrew Michell

unread,
Aug 16, 2024, 6:58:44 PM8/16/24
to fix8 support
Please disregard.  I just found there is a FIX8::MessageBase::remove method I can use the remove fields before the message is destructed.  I am able to use stack memory for both message and fields now.

Thanks,
Andrew

Reply all
Reply to author
Forward
0 new messages