From e15f959ddd6feb448ff5a93fb11124d291309395 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Sun, 23 May 2010 16:43:14 +0200 Subject: [PATCH] Save XML into message by extract_TReturnedMessage() This is precious work because we cannot deallocate the XML tree twice. --- src/isds.c | 22 +++++++++++++++++----- src/isds.h | 6 ++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/isds.c b/src/isds.c index 0fe8dd2..fec63b5 100644 --- a/src/isds.c +++ b/src/isds.c @@ -3492,7 +3492,8 @@ leave: /* Convert XSD tReturnedMessage XML tree into message structure. - * It doea not store XML tree into message->raw. + * It does not store serialized XML tree into message->raw. + * It does store (pointer to) parsed XML tree into message->xml if needed. * @context is ISDS context * @include_documents Use true if documents must be extracted * (tReturnedMessage XSD type), use false if documents shall be ommited @@ -3540,6 +3541,9 @@ static isds_error extract_TReturnedMessage(struct isds_ctx *context, if (err) { err = IE_ERROR; goto leave; } err = extract_documents(context, &((*message)->documents), xpath_ctx); if (err) goto leave; + /* Store xmlDoc of this message if needed */ + /* FIXME: Only if needed */ + (*message)->xml = xpath_ctx->doc; } @@ -7108,7 +7112,9 @@ leave: free(code); free(status_message); - xmlFreeDoc(response); + if (!*message || !(*message)->xml) { + xmlFreeDoc(response); + } if (!err) isds_log(ILF_ISDS, ILL_DEBUG, @@ -7280,7 +7286,9 @@ leave: xmlXPathFreeObject(result); xmlXPathFreeContext(xpath_ctx); - xmlFreeDoc(message_doc); + if (!*message || !(*message)->xml) { + xmlFreeDoc(message_doc); + } if (xml_stream != buffer) _isds_cms_data_free(xml_stream); if (!err) @@ -7554,7 +7562,9 @@ leave: free(code); free(status_message); free(xml_stream); - xmlFreeDoc(response); + if (!*message || !(*message)->xml) { + xmlFreeDoc(response); + } if (!err) isds_log(ILF_ISDS, ILL_DEBUG, @@ -7751,7 +7761,9 @@ leave: if (xml_stream != buffer) _isds_cms_data_free(xml_stream); xmlXPathFreeObject(result); xmlXPathFreeContext(xpath_ctx); - xmlFreeDoc(message_doc); + if (!*message || !(*message)->xml) { + xmlFreeDoc(message_doc); + } if (!err) isds_log(ILF_ISDS, ILL_DEBUG, _("Message loaded successfully.\n")); diff --git a/src/isds.h b/src/isds.h index 4cadb53..73a5c0a 100644 --- a/src/isds.h +++ b/src/isds.h @@ -487,10 +487,8 @@ struct isds_message { isds_raw_type raw_type; /* Content type of raw representation Meaningfull only with non-NULL raw member */ - xmlDocPtr xml; /* Message as parsed XML document while - getting message. - Parsed XML document with attached message - XML documents. + xmlDocPtr xml; /* Parsed XML document with attached ISDS + message XML documents. Can be NULL. May be freed AFTER deallocating documents member structure. */ struct isds_envelope *envelope; /* Message envelope */ -- 2.11.4.GIT