summaryrefslogtreecommitdiffstats
path: root/src/xml
diff options
context:
space:
mode:
authorKris De Gussem <kris.degussem@gmail.com>2012-09-20 20:40:55 +0000
committerKris <Kris.De.Gussem@hotmail.com>2012-09-20 20:40:55 +0000
commitbac4df147de363a0774548acd63d367a09ab50d3 (patch)
tree849f3bc54cfa4ba5d9e219173bcc5d5240b38375 /src/xml
parentTranslations. inkscape.pot update. (diff)
downloadinkscape-bac4df147de363a0774548acd63d367a09ab50d3.tar.gz
inkscape-bac4df147de363a0774548acd63d367a09ab50d3.zip
some memleak fixes (Bug #1043571)
(bzr r11686)
Diffstat (limited to 'src/xml')
-rw-r--r--src/xml/repr-css.cpp29
-rw-r--r--src/xml/repr.h2
-rw-r--r--src/xml/simple-node.cpp7
3 files changed, 14 insertions, 24 deletions
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp
index 594ac83c6..7fba4d7c6 100644
--- a/src/xml/repr-css.cpp
+++ b/src/xml/repr-css.cpp
@@ -270,10 +270,9 @@ double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double def
/**
* Write a style attribute string from a list of properties stored in an SPCSAttr object.
*/
-gchar *sp_repr_css_write_string(SPCSSAttr *css)
+void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str)
{
- Glib::ustring buffer;
-
+ str.clear();
for ( List<AttributeRecord const> iter = css->attributeList() ;
iter ; ++iter )
{
@@ -281,26 +280,21 @@ gchar *sp_repr_css_write_string(SPCSSAttr *css)
continue;
}
- buffer.append(g_quark_to_string(iter->key));
- buffer.push_back(':');
+ str.append(g_quark_to_string(iter->key));
+ str.push_back(':');
if (!strcmp(g_quark_to_string(iter->key), "font-family")
|| !strcmp(g_quark_to_string(iter->key), "-inkscape-font-specification")) {
// we only quote font-family/font-specification, as SPStyle does
- gchar *val_quoted = css2_escape_quote (iter->value);
- if (val_quoted) {
- buffer.append(val_quoted);
- g_free (val_quoted);
- }
+ Glib::ustring val_quoted = css2_escape_quote (iter->value);
+ str.append(val_quoted);
} else {
- buffer.append(iter->value); // unquoted
+ str.append(iter->value); // unquoted
}
if (rest(iter)) {
- buffer.push_back(';');
+ str.push_back(';');
}
}
-
- return (buffer.empty() ? NULL : g_strdup (buffer.c_str()));
}
/**
@@ -312,7 +306,8 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr)
g_assert(css != NULL);
g_assert(attr != NULL);
- gchar *value = sp_repr_css_write_string(css);
+ Glib::ustring value;
+ sp_repr_css_write_string(css, value);
/*
* If the new value is different from the old value, this will sometimes send a signal via
@@ -320,9 +315,7 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr)
* SPObject::sp_object_repr_attr_changed and thus updates the object's SPStyle. This update
* results in another call to repr->setAttribute().
*/
- repr->setAttribute(attr, value);
-
- if (value) g_free (value);
+ repr->setAttribute(attr, value.c_str());
}
/**
diff --git a/src/xml/repr.h b/src/xml/repr.h
index 86a798e3e..debd0f489 100644
--- a/src/xml/repr.h
+++ b/src/xml/repr.h
@@ -79,7 +79,7 @@ void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name);
bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name);
double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval);
-gchar *sp_repr_css_write_string(SPCSSAttr *css);
+void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str);
void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src);
void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const gchar *data);
diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp
index c197d648b..55bd28afe 100644
--- a/src/xml/simple-node.cpp
+++ b/src/xml/simple-node.cpp
@@ -318,8 +318,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_
// Check usefulness of attributes on elements in the svg namespace, optionally don't add them to tree.
Glib::ustring element = g_quark_to_string(_name);
- //g_warning("setAttribute: %s: %s: %s", element.c_str(), name, value);
-
+ // g_message("setAttribute: %s: %s: %s", element.c_str(), name, value);
gchar* cleaned_value = g_strdup( value );
// Only check elements in SVG name space and don't block setting attribute to NULL.
@@ -347,7 +346,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_
// tree (and thus has no parent), default values will not be tested.
if( !strcmp( name, "style" ) && (flags >= SP_ATTR_CLEAN_STYLE_WARN) ) {
g_free( cleaned_value );
- cleaned_value = sp_attribute_clean_style( this, value, flags );
+ cleaned_value = const_cast<char*>(sp_attribute_clean_style( this, value, flags ).c_str());
// if( g_strcmp0( value, cleaned_value ) ) {
// g_warning( "SimpleNode::setAttribute: %s", id.c_str() );
// g_warning( " original: %s", value);
@@ -401,9 +400,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_
_observers.notifyAttributeChanged(*this, key, old_value, new_value);
//g_warning( "setAttribute notified: %s: %s: %s: %s", name, element.c_str(), old_value, new_value );
}
-
g_free( cleaned_value );
-
}
void SimpleNode::addChild(Node *generic_child, Node *generic_ref) {