summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-09-28 17:18:11 +0100
committerRichard Hughes <richard@hughsie.com>2016-09-28 17:18:49 +0100
commit57f6d00ff98cdc5e70913701b8a70d47b3e5649b (patch)
tree0fa0d5988c9226d8c7ecc02d0759a46a45ca4051
parentf0990480624f7f76f6d82a4d1d7356464e340880 (diff)
downloadappstream-glib-57f6d00ff98cdc5e70913701b8a70d47b3e5649b.tar.gz
Fix a small memory leak when parsing yaml files
-rw-r--r--libappstream-glib/as-app.c4
-rw-r--r--libappstream-glib/as-node-private.h3
-rw-r--r--libappstream-glib/as-node.c17
-rw-r--r--libappstream-glib/as-self-test.c36
-rw-r--r--libappstream-glib/as-store.c6
5 files changed, 43 insertions, 23 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index a44bd9f..1bb6aff 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -5451,7 +5451,7 @@ as_app_parse_appdata_file (AsApp *app,
gchar *tmp;
gsize len;
g_autoptr(GError) error_local = NULL;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autofree gchar *data = NULL;
g_autoptr(AsNode) root = NULL;
@@ -5639,7 +5639,7 @@ as_app_to_file (AsApp *app,
GCancellable *cancellable,
GError **error)
{
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsNode) root = NULL;
g_autoptr(GString) xml = NULL;
diff --git a/libappstream-glib/as-node-private.h b/libappstream-glib/as-node-private.h
index 8a405b8..9d72633 100644
--- a/libappstream-glib/as-node-private.h
+++ b/libappstream-glib/as-node-private.h
@@ -33,6 +33,7 @@ G_BEGIN_DECLS
typedef struct _AsNodeContext AsNodeContext;
AsNodeContext *as_node_context_new (void);
+void as_node_context_free (AsNodeContext *ctx);
gdouble as_node_context_get_version (AsNodeContext *ctx);
void as_node_context_set_version (AsNodeContext *ctx,
gdouble version);
@@ -56,6 +57,8 @@ gchar *as_node_reflow_text (const gchar *text,
gssize text_len);
gchar *as_node_fix_locale (const gchar *locale);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(AsNodeContext, as_node_context_free)
+
G_END_DECLS
#endif /* __AS_NODE_PRIVATE_H */
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c
index bceb7b2..9579bea 100644
--- a/libappstream-glib/as-node.c
+++ b/libappstream-glib/as-node.c
@@ -1949,6 +1949,23 @@ as_node_context_new (void)
}
/**
+ * as_node_context_free: (skip)
+ * @ctx: a #AsNodeContext.
+ *
+ * Frees the node context.
+ *
+ * Since: 0.6.4
+ **/
+void
+as_node_context_free (AsNodeContext *ctx)
+{
+ if (ctx == NULL)
+ return;
+ g_free (ctx->media_base_url);
+ g_free (ctx);
+}
+
+/**
* as_node_context_get_version: (skip)
* @ctx: a #AsNodeContext.
*
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index e2db1d0..4f6f307 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -451,7 +451,7 @@ as_test_release_func (void)
GString *xml;
const gchar *src = "<release timestamp=\"123\" urgency=\"critical\" version=\"0.1.2\"/>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsRelease) release = NULL;
release = as_release_new ();
@@ -498,7 +498,7 @@ as_test_release_date_func (void)
AsNode *root;
const gchar *src = "<release date=\"2016-01-18\"/>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsRelease) release = NULL;
release = as_release_new ();
@@ -528,7 +528,7 @@ as_test_provide_func (void)
GString *xml;
const gchar *src = "<binary>/usr/bin/gnome-shell</binary>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsProvide) provide = NULL;
provide = as_provide_new ();
@@ -582,7 +582,7 @@ as_test_release_appstream_func (void)
"<size type=\"installed\">123456</size>\n"
"<size type=\"download\">654321</size>\n"
"</release>\n";
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsRelease) release = NULL;
release = as_release_new ();
@@ -660,7 +660,7 @@ as_test_release_appdata_func (void)
"<p xml:lang=\"pl\">Oprogramowanie</p>\n"
"</description>\n"
"</release>\n";
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsRelease) release = NULL;
release = as_release_new ();
@@ -886,7 +886,7 @@ as_test_icon_func (void)
GString *xml;
const gchar *src = "<icon type=\"cached\">app.png</icon>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autofree gchar *prefix = NULL;
g_autoptr(AsIcon) icon = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
@@ -949,7 +949,7 @@ as_test_checksum_func (void)
GString *xml;
const gchar *src = "<checksum type=\"sha1\" filename=\"fn.cab\" target=\"container\">12345</checksum>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsChecksum) csum = NULL;
/* helpers */
@@ -1046,7 +1046,7 @@ as_test_icon_embedded_func (void)
"</filecontent>"
"</icon>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsIcon) icon = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
@@ -1109,7 +1109,7 @@ as_test_image_func (void)
"<image type=\"thumbnail\" height=\"12\" width=\"34\" xml:lang=\"en_GB\">"
"http://www.hughsie.com/a.jpg</image>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autofree gchar *filename = NULL;
g_autoptr(AsImage) image = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
@@ -1195,7 +1195,7 @@ as_test_review_func (void)
"</metadata>\n"
"</review>\n";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsReview) review = NULL;
review = as_review_new ();
@@ -1249,7 +1249,7 @@ as_test_suggest_func (void)
"<id>mypaint.desktop</id>\n"
"</suggests>\n";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsSuggest) suggest = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
@@ -1293,7 +1293,7 @@ as_test_bundle_func (void)
const gchar *src =
"<bundle type=\"limba\" runtime=\"1\" sdk=\"2\">gnome-3-16</bundle>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsBundle) bundle = NULL;
bundle = as_bundle_new ();
@@ -1338,7 +1338,7 @@ as_test_translation_func (void)
const gchar *src =
"<translation type=\"gettext\">gnome-software</translation>";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsTranslation) translation = NULL;
translation = as_translation_new ();
@@ -1387,7 +1387,7 @@ as_test_screenshot_func (void)
"<image type=\"thumbnail\" height=\"100\" width=\"100\">http://2.png</image>\n"
"</screenshot>\n";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsScreenshot) screenshot = NULL;
screenshot = as_screenshot_new ();
@@ -1447,7 +1447,7 @@ as_test_content_rating_func (void)
"<content_attribute id=\"violence-cartoon\">mild</content_attribute>\n"
"</content_rating>\n";
gboolean ret;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsContentRating) content_rating = NULL;
content_rating = as_content_rating_new ();
@@ -1577,7 +1577,7 @@ as_test_app_func (void)
"<value key=\"SomethingRandom\"/>\n"
"</metadata>\n"
"</component>\n";
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsApp) app = NULL;
app = as_app_new ();
@@ -2191,7 +2191,7 @@ as_test_app_no_markup_func (void)
"<id>org.gnome.Software.desktop</id>\n"
"<description>Software is awesome:\n\n * Bada\n * Boom!</description>\n"
"</component>\n";
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autoptr(AsApp) app = NULL;
app = as_app_new ();
@@ -3701,8 +3701,8 @@ as_test_node_no_dup_c_func (void)
"<name>Krita</name>"
"<name xml:lang=\"pl\">Krita</name>"
"</component>";
- g_autofree AsNodeContext *ctx = NULL;
g_autoptr(AsApp) app = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
/* to object */
app = as_app_new ();
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index de5aba1..44f15ed 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -1239,7 +1239,7 @@ as_store_from_root (AsStore *store,
const gchar *tmp;
const gchar *origin_delim = ":";
gchar *str;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autofree gchar *icon_path = NULL;
g_autofree gchar *id_prefix_app = NULL;
g_autofree gchar *origin_app = NULL;
@@ -1428,7 +1428,7 @@ as_store_load_yaml_file (AsStore *store,
AsNode *app_n;
AsNode *n;
const gchar *tmp;
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
g_autofree gchar *icon_path = NULL;
g_autoptr(AsYaml) root = NULL;
_cleanup_uninhibit_ guint32 *tok = NULL;
@@ -1980,7 +1980,7 @@ as_store_to_xml (AsStore *store, AsNodeToXmlFlags flags)
gboolean output_trusted = FALSE;
guint i;
gchar version[6];
- g_autofree AsNodeContext *ctx = NULL;
+ g_autoptr(AsNodeContext) ctx = NULL;
/* check categories of apps about to be written */
as_store_check_apps_for_veto (store);