[SOLVED] GLib / GUri : is that a bug?

Hello all,

I’m a beginner with GLib. I’m using 2.80 on Ubuntu Noble. I’m encountering a crash. Before filling a bug, I want to know if something is wrong with my code:

#include <stdio.h>
#include <glib.h>
#include <glib-object.h>

gboolean is_valid_uri(char const * uri_str)
{
	GError * error = NULL;
	GUri * const parsed_uri = g_uri_parse(uri_str, G_URI_FLAGS_NONE, &error);

	if (parsed_uri == NULL)
	{
		g_error_free(error);
		return FALSE;
	}

	g_object_unref(parsed_uri); // <-- CRASH IS HERE
	return TRUE;
}

int main(int ac, char ** av)
{
	printf("%d", is_valid_uri("https://gitlab.gnome.org"));
	return 0;
}

Am I right to believe that instances of GUri should be unrefed after use?
If so, is there anything else wrong with my code?

EDIT: Crash is actually a segfault.

A GUri is not a GObject, so you cannot use g_object_unref(); you should use g_uri_unref() instead.

Thanks a lot for your help : )

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.