Permalink
Browse files

Remove strdup.

No need for explicit use of strdup + free, the refs will be cleaned up
with the handles.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent 3a5ab4c commit bca13481fbf05783734170247f0a500b468d7ee8 @ncb000gt ncb000gt committed Jan 6, 2013
Showing with 18 additions and 21 deletions.
  1. +18 −21 src/xml_document.cc
View
@@ -96,34 +96,31 @@ XmlDocument::SetDtd(const v8::Arguments& args)
XmlDocument* document = ObjectWrap::Unwrap<XmlDocument>(args.Holder());
assert(document);
- v8::String::Utf8Value name(args[0]->ToString());
- //must be set to null in order for xmlCreateIntSubset to ignore them
- char* externalId = NULL;
- if (args.Length() > 1 && args[1]->IsString()) {
- v8::String::Utf8Value externalId_(args[1]->ToString());
- externalId = strdup(*externalId_);
- }
- char* systemId = NULL;
- if (args.Length() > 2 && args[2]->IsString()) {
- v8::String::Utf8Value systemId_(args[2]->ToString());
- systemId = strdup(*systemId_);
- }
+ v8::String::Utf8Value name(args[0]);
+
+ v8::Handle<v8::Value> extIdOpt;
+ v8::Handle<v8::Value> sysIdOpt;
+ if (args.Length() > 1 && args[1]->IsString()) {
+ extIdOpt = args[1];
+ }
+ if (args.Length() > 2 && args[2]->IsString()) {
+ sysIdOpt = args[2];
+ }
+
+ v8::String::Utf8Value extIdRaw(extIdOpt);
+ v8::String::Utf8Value sysIdRaw(sysIdOpt);
+
+ //must be set to null in order for xmlCreateIntSubset to ignore them
+ const char* extId = (extIdRaw.length()) ? *extIdRaw : NULL;
+ const char* sysId = (sysIdRaw.length()) ? *sysIdRaw : NULL;
//No good way of unsetting the doctype if it is previously set...this allows us to.
xmlDtdPtr dtd = xmlGetIntSubset(document->xml_obj);
xmlUnlinkNode((xmlNodePtr) dtd);
xmlFreeNode((xmlNodePtr) dtd);
-
- xmlCreateIntSubset(document->xml_obj, (const xmlChar *) *name, (const xmlChar *) externalId, (const xmlChar *) systemId);
-
- if (externalId != NULL) {
- free(externalId);
- }
- if (systemId != NULL) {
- free(systemId);
- }
+ xmlCreateIntSubset(document->xml_obj, (const xmlChar *) *name, (const xmlChar *) extId, (const xmlChar *) sysId);
return scope.Close(args.Holder());
}

0 comments on commit bca1348

Please sign in to comment.