Fix a nasty bug : fulfill reply data must be copied, not just referenced

This commit is contained in:
Grégory Soutadé 2021-11-26 20:01:49 +01:00
parent 8413b844db
commit fd8ce841eb
2 changed files with 12 additions and 3 deletions

View File

@ -34,6 +34,12 @@ namespace gourou
class FulfillmentItem class FulfillmentItem
{ {
public: public:
/**
* @brief Main constructor. Not to be called by user
*
* @param doc Fulfill reply
* @param user User pointer
*/
FulfillmentItem(pugi::xml_document& doc, User* user); FulfillmentItem(pugi::xml_document& doc, User* user);
/** /**
@ -59,6 +65,7 @@ namespace gourou
std::string getResource(); std::string getResource();
private: private:
pugi::xml_document fulfillDoc;
pugi::xml_node metadatas; pugi::xml_node metadatas;
pugi::xml_document rights; pugi::xml_document rights;
std::string downloadURL; std::string downloadURL;

View File

@ -24,8 +24,10 @@
namespace gourou namespace gourou
{ {
FulfillmentItem::FulfillmentItem(pugi::xml_document& doc, User* user) FulfillmentItem::FulfillmentItem(pugi::xml_document& doc, User* user)
: fulfillDoc()
{ {
metadatas = doc.select_node("//metadata").node(); fulfillDoc.reset(doc); /* We must keep a copy */
metadatas = fulfillDoc.select_node("//metadata").node();
if (!metadatas) if (!metadatas)
EXCEPTION(FFI_INVALID_FULFILLMENT_DATA, "No metadata tag in document"); EXCEPTION(FFI_INVALID_FULFILLMENT_DATA, "No metadata tag in document");