From 747795541ccf5caf9164921a3fe0fa4534ec6e45 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 2 Jan 2014 18:22:21 +0100 Subject: memory leak fix (doc_title) + code readability (bzr r12867) --- src/file.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/file.cpp') 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(selectionType); if (omod) { -- cgit v1.2.3 From 1a3923ceee80f32e42c677381138723b99278e1b Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 6 Jan 2014 22:42:55 +0100 Subject: c-string buffer > Glib::ustring usage (bzr r12885) --- src/file.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index cd52d0b86..babc4df99 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -855,23 +855,18 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extens Glib::ustring save_loc = save_path; save_loc.append(G_DIR_SEPARATOR_S); - // TODO fixed buffer is bad: - char formatBuf[256]; int i = 1; if ( !doc->getURI() ) { // We are saving for the first time; create a unique default filename - snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str()); - save_loc.append(formatBuf); + save_loc = save_loc + Glib::ustring(_("drawing")) + filename_extension; while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) { save_loc = save_path; save_loc.append(G_DIR_SEPARATOR_S); - snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str()); - save_loc.append(formatBuf); + save_loc = save_loc + Glib::ustring::compose(_("drawing-%1"), i++) + filename_extension; } } else { - snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->getURI()).c_str()); - save_loc.append(formatBuf); + save_loc.append(Glib::path_get_basename(doc->getURI())); } // convert save_loc from utf-8 to locale -- cgit v1.2.3