summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2010-07-28 01:57:53 +0000
committerJon A. Cruz <jon@joncruz.org>2010-07-28 01:57:53 +0000
commitb866548d43ef89eefbbec860e0935f8f2505277f (patch)
treeda03e6a0cdc3db53f5836d9c723ed4e3617ce9fa /src
parentDuplicate the undo key passed to sp_document_maybe_done, instead of simply (diff)
downloadinkscape-b866548d43ef89eefbbec860e0935f8f2505277f.tar.gz
inkscape-b866548d43ef89eefbbec860e0935f8f2505277f.zip
Safer fix for bug #579932 that won't leak memory.
(bzr r9662)
Diffstat (limited to 'src')
-rw-r--r--src/document-undo.cpp24
-rw-r--r--src/document.cpp8
-rw-r--r--src/document.h3
3 files changed, 18 insertions, 17 deletions
diff --git a/src/document-undo.cpp b/src/document-undo.cpp
index 62259fa19..e63fe8a52 100644
--- a/src/document-undo.cpp
+++ b/src/document-undo.cpp
@@ -125,11 +125,10 @@ sp_document_done (SPDocument *doc, const unsigned int event_type, Glib::ustring
sp_document_maybe_done (doc, NULL, event_type, event_description);
}
-void
-sp_document_reset_key (Inkscape::Application */*inkscape*/, SPDesktop */*desktop*/, GtkObject *base)
+void sp_document_reset_key( Inkscape::Application * /*inkscape*/, SPDesktop * /*desktop*/, GtkObject *base )
{
- SPDocument *doc = (SPDocument *) base;
- doc->actionkey = NULL;
+ SPDocument *doc = reinterpret_cast<SPDocument *>(base);
+ doc->actionkey.clear();
}
namespace {
@@ -171,6 +170,9 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
g_assert (doc != NULL);
g_assert (doc->priv != NULL);
g_assert (doc->priv->sensitive);
+ if ( key && !*key ) {
+ g_warning("Blank undo key specified.");
+ }
Inkscape::Debug::EventTracker<CommitEvent> tracker(doc, key, event_type);
@@ -188,7 +190,7 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
return;
}
- if (key && doc->actionkey && !strcmp (key, doc->actionkey) && doc->priv->undo) {
+ if (key && !doc->actionkey.empty() && (doc->actionkey == key) && doc->priv->undo) {
((Inkscape::Event *)doc->priv->undo->data)->event =
sp_repr_coalesce_log (((Inkscape::Event *)doc->priv->undo->data)->event, log);
} else {
@@ -198,9 +200,11 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
doc->priv->undoStackObservers.notifyUndoCommitEvent(event);
}
- if (doc->actionkey)
- g_free(doc->actionkey);
- doc->actionkey = key ? g_strdup(key) : NULL;
+ if ( key ) {
+ doc->actionkey = key;
+ } else {
+ doc->actionkey.clear();
+ }
doc->virgin = FALSE;
doc->setModifiedSinceSave();
@@ -259,7 +263,7 @@ sp_document_undo (SPDocument *doc)
doc->priv->sensitive = FALSE;
doc->priv->seeking = true;
- doc->actionkey = NULL;
+ doc->actionkey.clear();
finish_incomplete_transaction(*doc);
@@ -305,7 +309,7 @@ sp_document_redo (SPDocument *doc)
doc->priv->sensitive = FALSE;
doc->priv->seeking = true;
- doc->actionkey = NULL;
+ doc->actionkey.clear();
finish_incomplete_transaction(*doc);
diff --git a/src/document.cpp b/src/document.cpp
index eebc50a98..3c9f7e5ed 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -92,7 +92,7 @@ SPDocument::SPDocument() :
base(0),
name(0),
priv(0), // reset in ctor
- actionkey(0),
+ actionkey(),
modified_id(0),
rerouting_handler_id(0),
profileManager(0), // deferred until after other initialization
@@ -211,10 +211,6 @@ SPDocument::~SPDocument() {
inkscape_unref();
keepalive = FALSE;
}
- if (actionkey) {
- g_free(actionkey);
- actionkey = NULL;
- }
//delete this->_whiteboard_session_manager;
}
@@ -291,7 +287,7 @@ void SPDocument::collectOrphans() {
void SPDocument::reset_key (void */*dummy*/)
{
- actionkey = NULL;
+ actionkey.clear();
}
SPDocument *
diff --git a/src/document.h b/src/document.h
index bcc072f70..5810b5358 100644
--- a/src/document.h
+++ b/src/document.h
@@ -96,7 +96,8 @@ struct SPDocument : public Inkscape::GC::Managed<>,
SPDocumentPrivate *priv;
/// Last action key
- gchar *actionkey;
+ Glib::ustring actionkey;
+
/// Handler ID
guint modified_id;