Fixed possible segfault (thanks to John van der Kamp, from Zarafa).

This commit is contained in:
Vincent Richard 2009-09-15 19:36:03 +00:00
parent b4d964c63b
commit ac6865fe36

View File

@ -142,6 +142,9 @@ ref <message> messageBuilder::construct() const
{ {
const bodyPart& part = *msg->getBody()->getPartAt(0); const bodyPart& part = *msg->getBody()->getPartAt(0);
// Make a full copy of the body, otherwise the copyFrom() will delete the body we're copying
ref <body> bodyCopy = part.getBody()->clone().dynamicCast <body>();
// First, copy (and replace) the header fields // First, copy (and replace) the header fields
const std::vector <ref <const headerField> > fields = part.getHeader()->getFieldList(); const std::vector <ref <const headerField> > fields = part.getHeader()->getFieldList();
@ -153,7 +156,7 @@ ref <message> messageBuilder::construct() const
// Second, copy the body contents and sub-parts (this also remove // Second, copy the body contents and sub-parts (this also remove
// the body part we are copying...) // the body part we are copying...)
msg->getBody()->copyFrom(*part.getBody()); msg->getBody()->copyFrom(*bodyCopy);
} }
return (msg); return (msg);