summaryrefslogtreecommitdiff
path: root/src/pugixml.cpp
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 /src/pugixml.cpp
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
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r--src/pugixml.cpp18
1 files changed, 17 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);