diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2012-09-20 20:40:55 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2012-09-20 20:40:55 +0000 |
| commit | bac4df147de363a0774548acd63d367a09ab50d3 (patch) | |
| tree | 849f3bc54cfa4ba5d9e219173bcc5d5240b38375 /src | |
| parent | Translations. inkscape.pot update. (diff) | |
| download | inkscape-bac4df147de363a0774548acd63d367a09ab50d3.tar.gz inkscape-bac4df147de363a0774548acd63d367a09ab50d3.zip | |
some memleak fixes (Bug #1043571)
(bzr r11686)
Diffstat (limited to 'src')
| -rw-r--r-- | src/attribute-rel-util.cpp | 17 | ||||
| -rw-r--r-- | src/attribute-rel-util.h | 2 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.cpp | 20 | ||||
| -rw-r--r-- | src/id-clash.cpp | 7 | ||||
| -rw-r--r-- | src/preferences.cpp | 12 | ||||
| -rw-r--r-- | src/sp-object.cpp | 10 | ||||
| -rw-r--r-- | src/style.cpp | 12 | ||||
| -rw-r--r-- | src/style.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/style-swatch.cpp | 17 | ||||
| -rw-r--r-- | src/xml/repr-css.cpp | 29 | ||||
| -rw-r--r-- | src/xml/repr.h | 2 | ||||
| -rw-r--r-- | src/xml/simple-node.cpp | 7 |
12 files changed, 61 insertions, 76 deletions
diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 239e359e2..cf94c0c1e 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -128,17 +128,13 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { // Find element's style SPCSSAttr *css = sp_repr_css_attr( repr, "style" ); - sp_attribute_clean_style(repr, css, flags); - // g_warning( "sp_repr_write_stream_element(): Final style:" ); - //sp_repr_css_print( css ); - // Convert css node's properties data to string and set repr node's attribute "style" to that string. // sp_repr_css_set( repr, css, "style"); // Don't use as it will cause loop. - gchar *value = sp_repr_css_write_string(css); - repr->setAttribute("style", value); - if (value) g_free (value); + Glib::ustring value; + sp_repr_css_write_string(css, value); + repr->setAttribute("style", value.c_str()); sp_repr_css_attr_unref( css ); } @@ -147,7 +143,7 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { /** * Clean CSS style on an element. */ -gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { +Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { g_return_val_if_fail (repr != NULL, NULL); g_return_val_if_fail (repr->type() == Inkscape::XML::ELEMENT_NODE, NULL); @@ -155,11 +151,12 @@ gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int f SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string( css, string ); sp_attribute_clean_style(repr, css, flags); - gchar* string_cleaned = sp_repr_css_write_string( css ); + Glib::ustring string_cleaned; + sp_repr_css_write_string (css, string_cleaned); sp_repr_css_attr_unref( css ); - return string_cleaned; + return string_cleaned; } diff --git a/src/attribute-rel-util.h b/src/attribute-rel-util.h index d9d270a13..449a66d9e 100644 --- a/src/attribute-rel-util.h +++ b/src/attribute-rel-util.h @@ -61,7 +61,7 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags); /** * Clean style properties for one style string. */ -gchar* sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags); +Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags); /** * Clean style properties for one CSS. diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 66d1c5dfa..56d1dfdbd 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -223,11 +223,12 @@ dbus_create_node (SPDesktop *desk, const gchar *type) */ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) { - SPCSSAttr *style = sp_desktop_get_style(object->desk, TRUE); if (style) { - newNode->setAttribute("style", sp_repr_css_write_string(style), TRUE); + Glib::ustring str; + sp_repr_css_write_string(style, str); + newNode->setAttribute("style", str.c_str(), TRUE); } else { newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", TRUE); @@ -530,7 +531,7 @@ gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** } /**************************************************************************** - ENVIORNMENT FUNCTIONS + ENVIRONMENT FUNCTIONS ****************************************************************************/ gdouble document_interface_document_get_width (DocumentInterface *object) @@ -547,7 +548,9 @@ document_interface_document_get_height (DocumentInterface *object) gchar *document_interface_document_get_css(DocumentInterface *object, GError ** /*error*/) { SPCSSAttr *current = (object->desk)->current; - return sp_repr_css_write_string(current); + Glib::ustring str; + sp_repr_css_write_string(current, str); + return (str.empty() ? NULL : g_strdup (str.c_str())); } gboolean document_interface_document_merge_css(DocumentInterface *object, @@ -768,7 +771,9 @@ document_interface_modify_css (DocumentInterface *object, gchar *shape, SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); sp_repr_css_set_property(oldstyle, cssattrb, newval); - node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE); + Glib::ustring str; + sp_repr_css_write_string (oldstyle, str); + node->setAttribute (style, str.c_str(), TRUE); return TRUE; } @@ -791,7 +796,10 @@ document_interface_merge_css (DocumentInterface *object, gchar *shape, SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); sp_repr_css_merge(oldstyle, newstyle); - node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE); + Glib::ustring str; + sp_repr_css_write_string (oldstyle, str); + node->setAttribute (style, str.c_str(), TRUE); + return TRUE; } diff --git a/src/id-clash.cpp b/src/id-clash.cpp index 05a3149fc..7a1e000fb 100644 --- a/src/id-clash.cpp +++ b/src/id-clash.cpp @@ -260,10 +260,9 @@ fix_up_refs(const refmap_type *refmap, const id_changelist_type &id_changes) gchar *url = g_strdup_printf("url(#%s)", obj->getId()); sp_repr_css_set_property(style, it->attr, url); g_free(url); - gchar *style_string = sp_repr_css_write_string(style); - it->elem->getRepr()->setAttribute("style", style_string); - g_free(style_string); - + Glib::ustring style_string; + sp_repr_css_write_string(style, style_string); + it->elem->getRepr()->setAttribute("style", style_string.c_str()); } else { g_assert(0); // shouldn't happen } diff --git a/src/preferences.cpp b/src/preferences.cpp index 4615fd6e1..1f985a629 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -489,18 +489,18 @@ void Preferences::setString(Glib::ustring const &pref_path, Glib::ustring const void Preferences::setStyle(Glib::ustring const &pref_path, SPCSSAttr *style) { - gchar *css_str = sp_repr_css_write_string(style); - _setRawValue(pref_path, css_str); - g_free(css_str); + Glib::ustring css_str; + sp_repr_css_write_string(style, css_str); + _setRawValue(pref_path, css_str.c_str()); } void Preferences::mergeStyle(Glib::ustring const &pref_path, SPCSSAttr *style) { SPCSSAttr *current = getStyle(pref_path); sp_repr_css_merge(current, style); - gchar *css_str = sp_repr_css_write_string(current); - _setRawValue(pref_path, css_str); - g_free(css_str); + Glib::ustring css_str; + sp_repr_css_write_string(current, css_str); + _setRawValue(pref_path, css_str.c_str()); sp_repr_css_attr_unref(current); } diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 892c89a15..9ceeaf262 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1031,15 +1031,9 @@ Inkscape::XML::Node * SPObject::sp_object_private_write(SPObject *object, Inksca if( prefs->getBool("/options/svgoutput/check_on_editing") ) { unsigned int flags = sp_attribute_clean_get_prefs(); - gchar *s_cleaned = sp_attribute_clean_style( repr, s, flags ); - - // g_warning("SPObject::sp_object_private_write: %s", object->getId() ); - // g_warning(" old: :%s:", repr->attribute("style") ); - // g_warning(" new: :%s:", s ); - // g_warning(" cleaned: :%s:", s_cleaned ); - + Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s, flags ); g_free( s ); - s = s_cleaned; + s = (s_cleaned.empty() ? NULL : g_strdup (s_cleaned.c_str())); } if( s == NULL || strcmp(s,"") == 0 ) { diff --git a/src/style.cpp b/src/style.cpp index 2facc86d8..616474298 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -3890,10 +3890,9 @@ sp_style_write_istring(gchar *p, gint const len, gchar const *const key, if (val->inherit) { res = g_snprintf(p, len, "%s:inherit;", key); } else { - gchar *val_quoted = css2_escape_quote(val->value); - if (val_quoted) { - res = g_snprintf(p, len, "%s:%s;", key, val_quoted); - g_free (val_quoted); + Glib::ustring val_quoted = css2_escape_quote(val->value); + if (~val_quoted.empty()) { + res = g_snprintf(p, len, "%s:%s;", key, val_quoted.c_str()); } } } @@ -4710,8 +4709,7 @@ attribute_unquote(gchar const *val) /** * Quote and/or escape string for writing to CSS (style=). Returned value must be g_free'd. */ -gchar * -css2_escape_quote(gchar const *val) { +Glib::ustring css2_escape_quote(gchar const *val) { Glib::ustring t; bool quote = false; @@ -4755,7 +4753,7 @@ css2_escape_quote(gchar const *val) { t.push_back('\''); } - return (t.empty() ? NULL : g_strdup (t.c_str())); + return t; } /* diff --git a/src/style.h b/src/style.h index 576167645..7c64ea3d8 100644 --- a/src/style.h +++ b/src/style.h @@ -617,7 +617,7 @@ void sp_style_unset_property_attrs(SPObject *o); void sp_style_set_property_url (SPObject *item, gchar const *property, SPObject *linked, bool recursive); gchar *attribute_unquote(gchar const *val); -gchar *css2_escape_quote(gchar const *val); +Glib::ustring css2_escape_quote(gchar const *val); #endif // SEEN_SP_STYLE_H diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 1ee26e803..857ae7019 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -227,8 +227,7 @@ StyleSwatch::setWatchedTool(const char *path, bool synthesize) } -void -StyleSwatch::setStyle(SPCSSAttr *css) +void StyleSwatch::setStyle(SPCSSAttr *css) { if (_css) sp_repr_css_attr_unref (_css); @@ -239,18 +238,18 @@ StyleSwatch::setStyle(SPCSSAttr *css) _css = sp_repr_css_attr_new(); sp_repr_css_merge(_css, css); - gchar const *css_string = sp_repr_css_write_string (_css); + Glib::ustring css_string; + sp_repr_css_write_string (_css, css_string); SPStyle *temp_spstyle = sp_style_new(SP_ACTIVE_DOCUMENT); - if (css_string) - sp_style_merge_from_style_string (temp_spstyle, css_string); - + if (~css_string.empty()) { + sp_style_merge_from_style_string (temp_spstyle, css_string.c_str()); + } + setStyle (temp_spstyle); - sp_style_unref (temp_spstyle); } -void -StyleSwatch::setStyle(SPStyle *query) +void StyleSwatch::setStyle(SPStyle *query) { _place[SS_FILL].remove(); _place[SS_STROKE].remove(); 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) { |
