Avoid using old values after parsing a new uri. Related: rhbz#1335239 --- src/spice-uri.c | 17 +++++++++++++---- tests/uri.c | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/spice-uri.c b/src/spice-uri.c index 3bdb502..9f793de 100644 --- a/src/spice-uri.c +++ b/src/spice-uri.c @@ -97,6 +97,15 @@ SpiceURI* spice_uri_new(void) return self; } +static void spice_uri_reset(SpiceURI *self) +{ + g_clear_pointer(&self->scheme, g_free); + g_clear_pointer(&self->hostname, g_free); + g_clear_pointer(&self->user, g_free); + g_clear_pointer(&self->password, g_free); + self->port = 0; +} + G_GNUC_INTERNAL gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error) { @@ -105,6 +114,9 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error) size_t len; g_return_val_if_fail(self != NULL, FALSE); + + spice_uri_reset(self); + g_return_val_if_fail(_uri != NULL, FALSE); uri = dup = g_strdup(_uri); @@ -333,10 +345,7 @@ static void spice_uri_finalize(GObject* obj) SpiceURI *self; self = G_TYPE_CHECK_INSTANCE_CAST(obj, SPICE_TYPE_URI, SpiceURI); - g_free(self->scheme); - g_free(self->hostname); - g_free(self->user); - g_free(self->password); + spice_uri_reset(self); G_OBJECT_CLASS (spice_uri_parent_class)->finalize (obj); } diff --git a/tests/uri.c b/tests/uri.c index b68f159..d57f072 100644 --- a/tests/uri.c +++ b/tests/uri.c @@ -87,6 +87,7 @@ static void test_spice_uri_ipv4_good(void) {"https://127.0.0.1", "https", "127.0.0.1", 3129, NULL, NULL, NULL}, {"127.0.0.1", "http", "127.0.0.1", 3128, NULL, NULL, NULL}, {"http://user:password@host:80", "http", "host", 80, "user", "password", NULL}, + {"https://host:42", "https", "host", 42, NULL, NULL, NULL}, /* tests resetting of username & password */ }; test_spice_uri_good(valid_test_cases, G_N_ELEMENTS(valid_test_cases)); -- 2.8.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel