summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2011-07-31 05:21:21 +0000
committerJon A. Cruz <jon@joncruz.org>2011-07-31 05:21:21 +0000
commitef9e5dcdd29b794de438155f43a0a3374b4d33a3 (patch)
treea3f6a6efecad1d36bdc988786b5db42f3abf7ed7 /src
parentBetter memory-leak fix by just changing member to Glib::ustring. Eliminates p... (diff)
downloadinkscape-ef9e5dcdd29b794de438155f43a0a3374b4d33a3.tar.gz
inkscape-ef9e5dcdd29b794de438155f43a0a3374b4d33a3.zip
Refactored createnewDocFromMem() to be C++ instead of C, removing potential for memory leaks.
(bzr r10523)
Diffstat (limited to 'src')
-rw-r--r--src/document.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/document.cpp b/src/document.cpp
index 4d1d8780a..b699f8afa 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -497,25 +497,21 @@ SPDocument *SPDocument::createNewDoc(gchar const *uri, unsigned int keepalive, b
SPDocument *SPDocument::createNewDocFromMem(gchar const *buffer, gint length, unsigned int keepalive)
{
- SPDocument *doc;
- Inkscape::XML::Document *rdoc;
- Inkscape::XML::Node *rroot;
- gchar *name;
-
- rdoc = sp_repr_read_mem(buffer, length, SP_SVG_NS_URI);
-
- /* If it cannot be loaded, return NULL without warning */
- if (rdoc == NULL) return NULL;
-
- rroot = rdoc->root();
- /* If xml file is not svg, return NULL without warning */
- /* fixme: destroy document */
- if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
-
- name = g_strdup_printf(_("Memory document %d"), ++doc_count);
+ SPDocument *doc = 0;
+
+ Inkscape::XML::Document *rdoc = sp_repr_read_mem(buffer, length, SP_SVG_NS_URI);
+ if ( rdoc ) {
+ // Only continue to create a non-null doc if it could be loaded
+ Inkscape::XML::Node *rroot = rdoc->root();
+ if ( strcmp(rroot->name(), "svg:svg") != 0 ) {
+ // If xml file is not svg, return NULL without warning
+ // TODO fixme: destroy document
+ } else {
+ Glib::ustring name = Glib::ustring::compose( _("Memory document %1"), ++doc_count );
+ doc = createDoc(rdoc, NULL, NULL, name.c_str(), keepalive);
+ }
+ }
- doc = createDoc(rdoc, NULL, NULL, name, keepalive);
- g_free(name);
return doc;
}