Boost logo

Boost Users :

Subject: Re: [Boost-users] How can I free memory allocated when deserializing with boost::archive::text_iarchive
From: Jeff Flinn (Jeffrey.Flinn_at_[hidden])
Date: 2013-02-05 08:11:03


A general comment on using this mailing list is to reply directly to the
message, and to put the library in question in square brackets such as
[serialization].

On 2/4/2013 9:29 PM, Adlai Shawareb wrote:
> Thanks for your reply. Here is a code sample:
>
> std::istringstream istr;
> <* put data into istr here *>
> boost::archive::text_iarchive ia(istr_);
>
> Message* p_temp;
> ia & p_temp;
> mpBaseIncomingMessage = p_temp; // mpBaseIncomingMessage is of type (Message *)
>
> mpIncomingMessage = static_cast<SystemMessage*>(mpBaseIncomingMessage); // mpIncomingMessage is a pointer to a class derived from Message
> mObjectCallbackMap.process(mpIncomingMessage->mEvent); // execute a callback for this event
> delete mpIncomingMessage; // delete the allocated memory
>
> We then see a crash on either the " mObjectCallbackMap.process..." line or the " delete mpIncomingMessage", but only when certain actions are taken by the system.
>
> Any thoughts would be greatly appreciated.

Serialization library is designed to work with symmetrically
serialized/de-serialized data. How are you serializing the Message*?

You can save yourself lots of time by using boost::polymorphic_downcast
in situations like your usage of static_cast above to ensure you
actually have a base pointer pointing to the derived type you think you
have.

Also creating a standalone minimal example demonstrating the problem
usually helps you detect where things have gone awry.

Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net