diff options
author | Michael Stahl <mst@openoffice.org> | 2011-01-19 20:27:24 +0100 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2011-01-19 20:27:24 +0100 |
commit | 2619efc1a738936ccead4fbf2a952b96e29a0025 (patch) | |
tree | f79fcd52ab4e9b6f8c5eaf4b057993ef9a776fc5 /unoxml/source/dom | |
parent | aa85497de77acae2c9e58d7339584dcd7665e425 (diff) |
xmlfix3: unoxml: fix CAttributesMap:
member pointer does not keep document alive.
also, if an attribute is unlinked, it is leaked.
Diffstat (limited to 'unoxml/source/dom')
-rw-r--r-- | unoxml/source/dom/attributesmap.cxx | 75 | ||||
-rw-r--r-- | unoxml/source/dom/attributesmap.hxx | 51 | ||||
-rw-r--r-- | unoxml/source/dom/element.cxx | 12 |
3 files changed, 85 insertions, 53 deletions
diff --git a/unoxml/source/dom/attributesmap.cxx b/unoxml/source/dom/attributesmap.cxx index 6f3ac9639cd3..5ed65bf10bfc 100644 --- a/unoxml/source/dom/attributesmap.cxx +++ b/unoxml/source/dom/attributesmap.cxx @@ -25,13 +25,17 @@ * ************************************************************************/ -#include "attributesmap.hxx" +#include <attributesmap.hxx> + #include <string.h> +#include <element.hxx> + + namespace DOM { - CAttributesMap::CAttributesMap(const CElement* aElement) - : m_pElement(aElement) + CAttributesMap::CAttributesMap(::rtl::Reference<CElement> const& pElement) + : m_pElement(pElement) { } @@ -52,13 +56,13 @@ namespace DOM } } return count; - } /** Retrieves a node specified by local name */ - Reference< XNode > SAL_CALL CAttributesMap::getNamedItem(const OUString& name) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::getNamedItem(OUString const& name) throw (RuntimeException) { Reference< XNode > aNode; xmlNodePtr pNode = m_pElement->m_aNodePtr; @@ -84,7 +88,10 @@ namespace DOM /** Retrieves a node specified by local name and namespace URI. */ - Reference< XNode > SAL_CALL CAttributesMap::getNamedItemNS(const OUString& namespaceURI,const OUString& localName) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::getNamedItemNS( + OUString const& namespaceURI, OUString const& localName) + throw (RuntimeException) { Reference< XNode > aNode; xmlNodePtr pNode = m_pElement->m_aNodePtr; @@ -114,7 +121,8 @@ namespace DOM /** Returns the indexth item in the map. */ - Reference< XNode > SAL_CALL CAttributesMap::item(sal_Int32 index) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::item(sal_Int32 index) throw (RuntimeException) { Reference< XNode > aNode; xmlNodePtr pNode = m_pElement->m_aNodePtr; @@ -135,16 +143,16 @@ namespace DOM } } return aNode; - } /** Removes a node specified by name. */ - Reference< XNode > SAL_CALL CAttributesMap::removeNamedItem(const OUString& name) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::removeNamedItem(OUString const& name) + throw (RuntimeException) { - Reference< XNode > aNode; - xmlNodePtr pNode = m_pElement->m_aNodePtr; + xmlNodePtr const pNode = m_pElement->m_aNodePtr; if (pNode != NULL) { OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8); @@ -152,26 +160,29 @@ namespace DOM xmlAttrPtr cur = pNode->properties; while (cur != NULL) { - if( strcmp((char*)xName, (char*)cur->name) == 0) - { - aNode = Reference< XNode >( CNode::getCNode( - reinterpret_cast<xmlNodePtr>(cur)).get() ); - xmlUnlinkNode((xmlNodePtr)cur); - break; + if (strcmp((char*)xName, (char*)cur->name) == 0) { + ::rtl::Reference<CNode> const pCNode = CNode::getCNode( + reinterpret_cast<xmlNodePtr>(cur)).get(); + // this seems to be legal... + xmlUnlinkNode(reinterpret_cast<xmlNodePtr>(cur)); + pCNode->m_bUnlinked = true; + return Reference< XNode >(pCNode.get()); } cur = cur->next; } } - return aNode; + return 0; } /** // Removes a node specified by local name and namespace URI. */ - Reference< XNode > SAL_CALL CAttributesMap::removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::removeNamedItemNS( + OUString const& namespaceURI, OUString const& localName) + throw (RuntimeException) { - Reference< XNode > aNode; - xmlNodePtr pNode = m_pElement->m_aNodePtr; + xmlNodePtr const pNode = m_pElement->m_aNodePtr; if (pNode != NULL) { OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8); @@ -182,24 +193,28 @@ namespace DOM xmlAttrPtr cur = pNode->properties; while (cur != NULL && pNs != NULL) { - if( strcmp((char*)xName, (char*)cur->name) == 0 && + if (strcmp((char*)xName, (char*)cur->name) == 0 && cur->ns == pNs) { - aNode = Reference< XNode >( CNode::getCNode( - reinterpret_cast<xmlNodePtr>(cur)).get() ); - xmlUnlinkNode((xmlNodePtr)cur); - break; + ::rtl::Reference<CNode> const pCNode = CNode::getCNode( + reinterpret_cast<xmlNodePtr>(cur)).get(); + // this seems to be legal... + xmlUnlinkNode(reinterpret_cast<xmlNodePtr>(cur)); + pCNode->m_bUnlinked = true; + return Reference< XNode >(pCNode.get()); } cur = cur->next; } } - return aNode; + return 0; } /** // Adds a node using its nodeName attribute. */ - Reference< XNode > SAL_CALL CAttributesMap::setNamedItem(const Reference< XNode >& arg) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::setNamedItem(Reference< XNode > const& arg) + throw (RuntimeException) { return arg; // return Reference< XNode >(); @@ -208,7 +223,9 @@ namespace DOM /** Adds a node using its namespaceURI and localName. */ - Reference< XNode > SAL_CALL CAttributesMap::setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException) + Reference< XNode > SAL_CALL + CAttributesMap::setNamedItemNS(Reference< XNode > const& arg) + throw (RuntimeException) { return arg; // return Reference< XNode >(); diff --git a/unoxml/source/dom/attributesmap.hxx b/unoxml/source/dom/attributesmap.hxx index d19b517251a0..d61b96213785 100644 --- a/unoxml/source/dom/attributesmap.hxx +++ b/unoxml/source/dom/attributesmap.hxx @@ -25,19 +25,18 @@ * ************************************************************************/ -#ifndef _ATTRIBUTESMAP_HXX -#define _ATTRIBUTESMAP_HXX +#ifndef DOM_ATTRIBUTESMAP_HXX +#define DOM_ATTRIBUTESMAP_HXX -#include <map> #include <sal/types.h> -#include <cppuhelper/implbase1.hxx> +#include <rtl/ref.hxx> + #include <com/sun/star/uno/Reference.h> -#include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/xml/dom/XNode.hpp> #include <com/sun/star/xml/dom/XNamedNodeMap.hpp> -#include "node.hxx" -#include "element.hxx" -#include "attr.hxx" + +#include <cppuhelper/implbase1.hxx> + using ::rtl::OUString; using namespace com::sun::star::uno; @@ -45,12 +44,16 @@ using namespace com::sun::star::xml::dom; namespace DOM { - class CAttributesMap : public cppu::WeakImplHelper1< XNamedNodeMap > + class CElement; + + class CAttributesMap + : public cppu::WeakImplHelper1< XNamedNodeMap > { private: - const CElement* m_pElement; + ::rtl::Reference<CElement> const m_pElement; + public: - CAttributesMap(const CElement* aDocType); + CAttributesMap(::rtl::Reference<CElement> const& pElement); /** The number of nodes in this map. @@ -60,37 +63,49 @@ namespace DOM /** Retrieves a node specified by local name */ - virtual Reference< XNode > SAL_CALL getNamedItem(const OUString& name) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL getNamedItem(OUString const& name) + throw (RuntimeException); /** Retrieves a node specified by local name and namespace URI. */ - virtual Reference< XNode > SAL_CALL getNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL getNamedItemNS( + OUString const& namespaceURI, OUString const& localName) + throw (RuntimeException); /** Returns the indexth item in the map. */ - virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL item(sal_Int32 index) + throw (RuntimeException); /** Removes a node specified by name. */ - virtual Reference< XNode > SAL_CALL removeNamedItem(const OUString& name) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL + removeNamedItem(OUString const& name) + throw (RuntimeException); /** // Removes a node specified by local name and namespace URI. */ - virtual Reference< XNode > SAL_CALL removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL removeNamedItemNS( + OUString const& namespaceURI, OUString const& localName) + throw (RuntimeException); /** // Adds a node using its nodeName attribute. */ - virtual Reference< XNode > SAL_CALL setNamedItem(const Reference< XNode >& arg) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL + setNamedItem(Reference< XNode > const& arg) + throw (RuntimeException); /** Adds a node using its namespaceURI and localName. */ - virtual Reference< XNode > SAL_CALL setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException); + virtual Reference< XNode > SAL_CALL + setNamedItemNS(Reference< XNode > const& arg) + throw (RuntimeException); }; } diff --git a/unoxml/source/dom/element.cxx b/unoxml/source/dom/element.cxx index f7a7f8ca7efc..4267579bf934 100644 --- a/unoxml/source/dom/element.cxx +++ b/unoxml/source/dom/element.cxx @@ -625,14 +625,14 @@ namespace DOM } } - Reference< XNamedNodeMap > SAL_CALL CElement::getAttributes()throw (RuntimeException) + Reference< XNamedNodeMap > SAL_CALL + CElement::getAttributes() throw (RuntimeException) { - Reference< XNamedNodeMap > aMap; - if (hasAttributes()) { - aMap = Reference< XNamedNodeMap >(new CAttributesMap(this)); - } - return aMap; + if (!hasAttributes()) { return 0; } + Reference< XNamedNodeMap > const xMap(new CAttributesMap(this)); + return xMap; } + OUString SAL_CALL CElement::getNodeName()throw (RuntimeException) { return getLocalName(); |