Skip to content

Commit

Permalink
second round of memory updates. libxml memory is being cleaned up by …
Browse files Browse the repository at this point in the history
…v8 GC
  • Loading branch information
polotek committed May 21, 2010
1 parent 393b44a commit 63ec543
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/xml_attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ XmlAttribute::New(const v8::Arguments& args) {
(const xmlChar*)*name,
(const xmlChar*)*value);

UpdateV8Memory();

// namespace passed in
if (args.Length() == 4 && args[3]->IsObject()) {
XmlNamespace *ns = LibXmlObj::Unwrap<XmlNamespace>(args[3]->ToObject());
Expand Down
7 changes: 6 additions & 1 deletion src/xml_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ XmlDocument::New(const v8::Arguments& args) {
version = new v8::String::Utf8Value(v8::String::New("1.0"));

xmlDoc* doc = xmlNewDoc((const xmlChar*)**version);

UpdateV8Memory();

v8::Persistent<v8::Object> obj =
LXJS_GET_MAYBE_BUILD(XmlDocument, doc);
XmlDocument *document = LibXmlObj::Unwrap<XmlDocument>(obj);
Expand All @@ -156,11 +159,13 @@ XmlDocument::New(const v8::Arguments& args) {

XmlDocument::~XmlDocument() {
xmlFreeDoc(xml_obj);
UpdateV8Memory();
}

void
XmlDocument::set_encoding(const char* encoding) {
xml_obj->encoding = xmlStrdup((const xmlChar*)encoding);
if(xml_obj->encoding != NULL) xmlFree((xmlChar*)xml_obj->encoding);
xml_obj->encoding = xmlStrdup((const xmlChar*)encoding);
}

v8::Handle<v8::Value>
Expand Down
8 changes: 6 additions & 2 deletions src/xml_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ XmlElement::Attr(const v8::Arguments& args) {
}
break;

// 1 or 2 arguments only dude
// 1 argument only dude
default:
LIBXMLJS_THROW_EXCEPTION(
"Bad argument(s): #attr(name) or #attr({name: value})");
Expand Down Expand Up @@ -144,7 +144,7 @@ XmlElement::AddChild(const v8::Arguments& args) {
child = element->import_element(child);

if(child == NULL) {
LIBXMLJS_THROW_EXCEPTION("Could not add child (%s). Failed to copy node to new Document.");
LIBXMLJS_THROW_EXCEPTION("Could not add child. Failed to copy node to new Document.");
}

element->add_child(child);
Expand Down Expand Up @@ -469,7 +469,11 @@ XmlElement::import_element(XmlElement *element) {
if(new_child == NULL) {
return NULL;
}

element->remove();

UpdateV8Memory();

return LibXmlObj::Unwrap<XmlElement>(LXJS_GET_MAYBE_BUILD(XmlElement, new_child));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/xml_namespace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ XmlNamespace::New(const v8::Arguments& args) {
(const xmlChar*)**href,
prefix ? (const xmlChar*)**prefix : NULL);

UpdateV8Memory();

if (prefix)
delete prefix;
delete href;
Expand Down

0 comments on commit 63ec543

Please sign in to comment.