You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/02/04 22:50:38 UTC
cvs commit: xml-xerces/c/src/xercesc/idom IDDeepNodeListPool.c IDDeepNodeListPool.hpp
tng 02/02/04 13:50:38
Modified: c/src/xercesc/idom IDDeepNodeListPool.c
IDDeepNodeListPool.hpp
Log:
[Bug 6114] Memory leaks on iDOM getElementsByTagName().
Revision Changes Path
1.2 +51 -58 xml-xerces/c/src/xercesc/idom/IDDeepNodeListPool.c
Index: IDDeepNodeListPool.c
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDDeepNodeListPool.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDDeepNodeListPool.c 1 Feb 2002 22:21:53 -0000 1.1
+++ IDDeepNodeListPool.c 4 Feb 2002 21:50:38 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,8 +56,11 @@
/**
* $Log: IDDeepNodeListPool.c,v $
- * Revision 1.1 2002/02/01 22:21:53 peiyongz
- * Initial revision
+ * Revision 1.2 2002/02/04 21:50:38 tng
+ * [Bug 6114] Memory leaks on iDOM getElementsByTagName().
+ *
+ * Revision 1.1.1.1 2002/02/01 22:21:53 peiyongz
+ * sane_include
*
* Revision 1.1 2001/06/04 14:55:32 tng
* IDOM: Add IRange and IDeepNodeList Support.
@@ -220,8 +223,8 @@
delete curElem->fData;
// Then delete the current element and move forward
- delete[] curElem->fKey2;
- delete[] curElem->fKey3;
+ delete [] curElem->fKey2;
+ delete [] curElem->fKey3;
delete curElem;
curElem = nextElem;
@@ -235,6 +238,17 @@
fIdCounter = 0;
}
+template <class TVal> void IDDeepNodeListPool<TVal>::cleanup()
+{
+ removeAll();
+
+ // Then delete the bucket list & hasher & id pointers list
+ delete [] fIdPtrs;
+ delete [] fBucketList;
+ delete fHash;
+}
+
+
// ---------------------------------------------------------------------------
// IDDeepNodeListPool: Getters
@@ -352,8 +366,24 @@
IDDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[hashVal];
while (curElem)
{
- if (fHash->equals(key1, curElem->fKey1) && (!XMLString::compareString(key2, curElem->fKey2)) && (!XMLString::compareString(key3, curElem->fKey3)))
+ //key2 and key3 are XMLCh*, compareString takes null pointer vs zero len string the same
+ //but we need them to be treated as different keys in this case
+ if (fHash->equals(key1, curElem->fKey1) && (!XMLString::compareString(key2, curElem->fKey2)) && (!XMLString::compareString(key3, curElem->fKey3))) {
+ if (!key2 || !curElem->fKey2) {
+ if (key2 || curElem->fKey2) {
+ curElem = curElem->fNext;
+ continue;
+ }
+ }
+ if (!key3 || !curElem->fKey3) {
+ if (key3 || curElem->fKey3) {
+ curElem = curElem->fNext;
+ continue;
+ }
+ }
+
return curElem;
+ }
curElem = curElem->fNext;
}
@@ -372,62 +402,25 @@
const IDDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[hashVal];
while (curElem)
{
- if (fHash->equals(key1, curElem->fKey1) && (!XMLString::compareString(key2, curElem->fKey2)) && (!XMLString::compareString(key3, curElem->fKey3)))
+ //key2 and key3 are XMLCh*, compareString takes null pointer vs zero len string the same
+ //but we need them to be treated as different keys in this case
+ if (fHash->equals(key1, curElem->fKey1) && (!XMLString::compareString(key2, curElem->fKey2)) && (!XMLString::compareString(key3, curElem->fKey3))) {
+ if (!key2 || !curElem->fKey2) {
+ if (key2 || curElem->fKey2) {
+ curElem = curElem->fNext;
+ continue;
+ }
+ }
+ if (!key3 || !curElem->fKey3) {
+ if (key3 || curElem->fKey3) {
+ curElem = curElem->fNext;
+ continue;
+ }
+ }
return curElem;
+ }
curElem = curElem->fNext;
}
return 0;
-}
-
-
-// ---------------------------------------------------------------------------
-// IDDeepNodeListPoolEnumerator: Constructors and Destructor
-// ---------------------------------------------------------------------------
-template <class TVal> IDDeepNodeListPoolEnumerator<TVal>::
-IDDeepNodeListPoolEnumerator(IDDeepNodeListPool<TVal>* const toEnum, const bool adopt)
- : fAdoptedElems(adopt), fCurIndex(0), fToEnum(toEnum)
-{
- //
- // Find the next available bucket element in the pool. We use the id
- // array since its very easy to enumerator through by just maintaining
- // an index. If the id counter is zero, then its empty and we leave the
- // current index to zero.
- //
- if (toEnum->fIdCounter)
- fCurIndex = 1;
-}
-
-template <class TVal> IDDeepNodeListPoolEnumerator<TVal>::~IDDeepNodeListPoolEnumerator()
-{
- if (fAdoptedElems)
- delete fToEnum;
-}
-
-
-// ---------------------------------------------------------------------------
-// IDDeepNodeListPoolEnumerator: Enum interface
-// ---------------------------------------------------------------------------
-template <class TVal> bool IDDeepNodeListPoolEnumerator<TVal>::hasMoreElements() const
-{
- // If our index is zero or past the end, then we are done
- if (!fCurIndex || (fCurIndex > fToEnum->fIdCounter))
- return false;
- return true;
-}
-
-template <class TVal> TVal& IDDeepNodeListPoolEnumerator<TVal>::nextElement()
-{
- // If our index is zero or past the end, then we are done
- if (!fCurIndex || (fCurIndex > fToEnum->fIdCounter))
- ThrowXML(NoSuchElementException, XMLExcepts::Enum_NoMoreElements);
-
- // Return the current element and bump the index
- return *fToEnum->fIdPtrs[fCurIndex++];
-}
-
-template <class TVal> void IDDeepNodeListPoolEnumerator<TVal>::Reset()
-{
- fCurIndex = 0;
-}
-
+}
\ No newline at end of file
1.2 +6 -59 xml-xerces/c/src/xercesc/idom/IDDeepNodeListPool.hpp
Index: IDDeepNodeListPool.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDDeepNodeListPool.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDDeepNodeListPool.hpp 1 Feb 2002 22:21:53 -0000 1.1
+++ IDDeepNodeListPool.hpp 4 Feb 2002 21:50:38 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,8 +56,11 @@
/*
* $Log: IDDeepNodeListPool.hpp,v $
- * Revision 1.1 2002/02/01 22:21:53 peiyongz
- * Initial revision
+ * Revision 1.2 2002/02/04 21:50:38 tng
+ * [Bug 6114] Memory leaks on iDOM getElementsByTagName().
+ *
+ * Revision 1.1.1.1 2002/02/01 22:21:53 peiyongz
+ * sane_include
*
* Revision 1.1 2001/06/04 14:55:32 tng
* IDOM: Add IRange and IDeepNodeList Support.
@@ -82,14 +85,9 @@
#include <xercesc/util/HashXMLCh.hpp>
#include <xercesc/util/HashPtr.hpp>
-// This hash table is modified from IDDeepNodeListPoolTableOf with first key as object ptr (IDOM_Node),
+// This hash table is modified from RefHash3KeysIdPool with first key as object ptr (IDOM_Node),
// second and third keys are both XMLCh* string
-//
-// Forward declare the enumerator so he can be our friend. Can you say
-// friend? Sure...
-//
-template <class TVal> class IDDeepNodeListPoolEnumerator;
template <class TVal> struct IDDeepNodeListPoolTableBucketElem;
@@ -165,6 +163,7 @@
bool isEmpty() const;
bool containsKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
void removeAll();
+ void cleanup();
// -----------------------------------------------------------------------
@@ -181,13 +180,6 @@
// -----------------------------------------------------------------------
unsigned int put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt);
-
-private :
- // -----------------------------------------------------------------------
- // Declare our friends
- // -----------------------------------------------------------------------
- friend class IDDeepNodeListPoolEnumerator<TVal>;
-
private:
// -----------------------------------------------------------------------
@@ -239,51 +231,6 @@
unsigned int fIdPtrsCount;
unsigned int fIdCounter;
};
-
-
-
-//
-// An enumerator for a value array. It derives from the basic enumerator
-// class, so that value vectors can be generically enumerated.
-//
-template <class TVal> class IDDeepNodeListPoolEnumerator : public XMLEnumerator<TVal>
-{
-public :
- // -----------------------------------------------------------------------
- // Constructors and Destructor
- // -----------------------------------------------------------------------
- IDDeepNodeListPoolEnumerator(IDDeepNodeListPool<TVal>* const toEnum, const bool adopt = false);
- ~IDDeepNodeListPoolEnumerator();
-
-
- // -----------------------------------------------------------------------
- // Enum interface
- // -----------------------------------------------------------------------
- bool hasMoreElements() const;
- TVal& nextElement();
- void Reset();
-
-
-private :
- // -----------------------------------------------------------------------
- // Data Members
- // fAdoptedElems
- // Indicates whether the values added are adopted or just referenced.
- // If adopted, then they are deleted when they are removed from the
- // hash table
- //
- // fCurIndex
- // This is the current index into the pool's id mapping array. This
- // is now we enumerate it.
- //
- // fToEnum
- // The name id pool that is being enumerated.
- // -----------------------------------------------------------------------
- bool fAdoptedElems;
- unsigned int fCurIndex;
- IDDeepNodeListPool<TVal>* fToEnum;
-};
-
#if !defined(XERCES_TMPLSINC)
#include <xercesc/idom/IDDeepNodeListPool.c>
#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org