Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #151 from SYSTRAN/memory_leaks

fix memory leaks
  • Loading branch information...
commit 4f7255d4c5d1c8e2a393560603def146cf758186 2 parents f4707b5 + 4e3755c
@defunctzombie defunctzombie authored
View
3  src/xml_namespace.cc
@@ -41,6 +41,9 @@ XmlNamespace::New(const v8::Arguments& args) {
(const xmlChar*)(href->operator*()),
prefix ? (const xmlChar*)(prefix->operator*()) : NULL);
+ delete prefix;
+ delete href;
+
XmlNamespace* namesp = new XmlNamespace(ns);
namesp->Wrap(args.Holder());
View
7 src/xml_node.cc
@@ -195,9 +195,10 @@ XmlNode::~XmlNode() {
XmlDocument* doc = static_cast<XmlDocument*>(xml_obj->doc->_private);
doc->unref();
- // We do not free the xmlNode here. It could still be part of a document
- // It will be freed when the doc is freed
- // xmlFree(xml_obj);
+ // We do not free the xmlNode here if it is linked to a document
+ // It will be freed when the doc is freed
+ if (xml_obj->parent == NULL)
+ xmlFreeNode(xml_obj);
}
v8::Handle<v8::Value>
View
10 src/xml_sax_parser.cc
@@ -23,7 +23,6 @@ namespace libxmljs {
XmlSaxParser::XmlSaxParser()
: context_(NULL)
- , sax_handler_(new xmlSAXHandler)
{
xmlSAXHandler tmp = {
0, // internalSubset;
@@ -60,7 +59,7 @@ XmlSaxParser::XmlSaxParser()
0 // SaxParserCallback::structured_error // serror
};
- *sax_handler_ = tmp;
+ sax_handler_ = tmp;
}
XmlSaxParser::~XmlSaxParser() {
@@ -163,7 +162,7 @@ XmlSaxParser::Push(const v8::Arguments& args) {
void
XmlSaxParser::initialize_push_parser() {
- context_ = xmlCreatePushParserCtxt(sax_handler_, NULL, NULL, 0, "");
+ context_ = xmlCreatePushParserCtxt(&sax_handler_, NULL, NULL, 0, "");
context_->replaceEntities = 1;
initializeContext();
}
@@ -197,9 +196,10 @@ XmlSaxParser::parse_string(const char* str,
context_ = xmlCreateMemoryParserCtxt(str, size);
initializeContext();
context_->replaceEntities = 1;
- context_->sax = sax_handler_;
+ xmlSAXHandler* old_sax = context_->sax;
+ context_->sax = &sax_handler_;
xmlParseDocument(context_);
- context_->sax = NULL;
+ context_->sax = old_sax;
releaseContext();
}
View
2  src/xml_sax_parser.h
@@ -101,7 +101,7 @@ class XmlSaxParser : public node::ObjectWrap {
xmlParserCtxt* context_;
- xmlSAXHandler* sax_handler_;
+ xmlSAXHandler sax_handler_;
};
} // namespace libxmljs
Please sign in to comment.
Something went wrong with that request. Please try again.