diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2014-01-02 17:22:21 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2014-01-02 17:22:21 +0000 |
| commit | 747795541ccf5caf9164921a3fe0fa4534ec6e45 (patch) | |
| tree | 85255eefea9fdfa2afc2bf103c26e694abbcb5ff | |
| parent | Fix for Bug #950781 (There is no disk in drive error when opening Inkscape in... (diff) | |
| download | inkscape-747795541ccf5caf9164921a3fe0fa4534ec6e45.tar.gz inkscape-747795541ccf5caf9164921a3fe0fa4534ec6e45.zip | |
memory leak fix (doc_title) + code readability
(bzr r12867)
| -rw-r--r-- | src/file.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/file.cpp b/src/file.cpp index cec634c9b..cd52d0b86 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -843,19 +843,16 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extens if (extension) filename_extension = extension->get_extension(); - Glib::ustring save_path; - Glib::ustring save_loc; - - save_path = Inkscape::Extension::get_file_save_path(doc, save_method); + Glib::ustring save_path = Inkscape::Extension::get_file_save_path(doc, save_method); if (!Inkscape::IO::file_test(save_path.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) - save_path = ""; + save_path.clear(); - if (save_path.size()<1) + if (save_path.empty()) save_path = g_get_home_dir(); - save_loc = save_path; + Glib::ustring save_loc = save_path; save_loc.append(G_DIR_SEPARATOR_S); // TODO fixed buffer is bad: @@ -882,7 +879,7 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extens // Inkscape::IO? Glib::ustring save_loc_local = Glib::filename_from_utf8(save_loc); - if ( save_loc_local.size() > 0) + if (!save_loc_local.empty()) save_loc = save_loc_local; //# Show the SaveAs dialog @@ -909,28 +906,27 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extens bool success = saveDialog->show(); if (!success) { delete saveDialog; + if(doc_title) g_free(doc_title); return success; } // set new title here (call RDF to ensure metadata and title element are updated) rdf_set_work_entity(doc, rdf_find_entity("title"), saveDialog->getDocTitle().c_str()); - // free up old string - if(doc_title) g_free(doc_title); Glib::ustring fileName = saveDialog->getFilename(); Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType(); delete saveDialog; - saveDialog = 0; + if(doc_title) g_free(doc_title); - if (fileName.size() > 0) { + if (!fileName.empty()) { Glib::ustring newFileName = Glib::filename_to_utf8(fileName); - if ( newFileName.size()>0 ) + if (!newFileName.empty()) fileName = newFileName; else - g_warning( "Error converting save filename to UTF-8." ); + g_warning( "Error converting filename for saving to UTF-8." ); Inkscape::Extension::Output *omod = dynamic_cast<Inkscape::Extension::Output *>(selectionType); if (omod) { |
