From ac6865fe365d03bc70f3257a795ecc8e18f2d85d Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 15 Sep 2009 19:36:03 +0000 Subject: [PATCH] Fixed possible segfault (thanks to John van der Kamp, from Zarafa). --- src/messageBuilder.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/messageBuilder.cpp b/src/messageBuilder.cpp index d6195547..a70372fb 100644 --- a/src/messageBuilder.cpp +++ b/src/messageBuilder.cpp @@ -142,6 +142,9 @@ ref messageBuilder::construct() const { 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 bodyCopy = part.getBody()->clone().dynamicCast (); + // First, copy (and replace) the header fields const std::vector > fields = part.getHeader()->getFieldList(); @@ -153,7 +156,7 @@ ref messageBuilder::construct() const // Second, copy the body contents and sub-parts (this also remove // the body part we are copying...) - msg->getBody()->copyFrom(*part.getBody()); + msg->getBody()->copyFrom(*bodyCopy); } return (msg);