From fb742ba06df651af26be2f4c9959b5116983317a Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Tue, 28 Jan 2014 15:06:20 +0100 Subject: [PATCH] Keep a local copy of the string in the envelope, so that the data does not go out of scope --- include/envelope.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/envelope.h b/include/envelope.h index c793eab..f66331f 100644 --- a/include/envelope.h +++ b/include/envelope.h @@ -18,6 +18,12 @@ namespace AMQP { class Envelope : public MetaData { protected: + /** + * The body (only used when string object was passed to constructor + * @var std::string + */ + std::string _str; + /** * Pointer to the body data (the memory buffer is not managed by the AMQP * library!) @@ -47,7 +53,7 @@ public: * Constructor based on a string * @param body */ - Envelope(const std::string &body) : MetaData(), _body(body.data()), _bodySize(body.size()) {} + Envelope(const std::string &body) : MetaData(), _str(body), _body(_str.data()), _bodySize(_str.size()) {} /** * Destructor