summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2006-12-08 14:38:34 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2006-12-08 14:38:34 +0000
commit0d7e7a54f60fa229b96e149734abae6afd873fbf (patch)
tree133f12c8040e4408960585a6d1371bcec11d1c26
parent1ea53e16dd8d4f37092813e8da7839b96f599bc6 (diff)
Fixed memory leak, correct behavior for several parse() on one parser
git-svn-id: http://pugixml.googlecode.com/svn/trunk@15 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--src/pugixml.cpp18
-rw-r--r--src/pugixml.hpp2
2 files changed, 19 insertions, 1 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index b77a21d..d0d581b 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -1870,6 +1870,14 @@ namespace pugi
xml_parser::~xml_parser()
{
+ free();
+ }
+
+ void xml_parser::free()
+ {
+ delete _buffer;
+ _buffer = 0;
+
xml_memory_block* current = _memory.next;
while (current)
@@ -1878,6 +1886,9 @@ namespace pugi
delete current;
current = next;
}
+
+ _memory.next = 0;
+ _memory.size = 0;
}
xml_parser::operator xml_node() const
@@ -1905,6 +1916,8 @@ namespace pugi
#ifndef PUGIXML_NO_STL
void xml_parser::parse(std::istream& stream,unsigned int optmsk)
{
+ free();
+
int length = 0, pos = stream.tellg();
stream.seekg(0, std::ios_base::end);
length = stream.tellg();
@@ -1920,6 +1933,8 @@ namespace pugi
char* xml_parser::parse(char* xmlstr,unsigned int optmsk)
{
+ free();
+
if(!xmlstr) return 0;
xml_allocator alloc(&_memory);
@@ -1935,9 +1950,10 @@ namespace pugi
char* xml_parser::parse(const transfer_ownership_tag&, char* xmlstr,unsigned int optmsk)
{
+ free();
+
if(!xmlstr) return 0;
- delete[] _buffer;
_buffer = xmlstr;
xml_allocator alloc(&_memory);
diff --git a/src/pugixml.hpp b/src/pugixml.hpp
index 739caaa..42a7950 100644
--- a/src/pugixml.hpp
+++ b/src/pugixml.hpp
@@ -507,6 +507,8 @@ namespace pugi
xml_parser(const xml_parser&);
const xml_parser& operator=(const xml_parser&);
+ void free(); ///< free memory
+
public:
/// Constructor.
/// \param optmsk - Options mask.