Keep a local copy of the string in the envelope, so that the data does not go out of scope

This commit is contained in:
Martijn Otto 2014-01-28 15:06:20 +01:00
parent 42f61a65bf
commit fb742ba06d
1 changed files with 7 additions and 1 deletions

View File

@ -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