From c3d36ee186b5fb24480590080215f7e14ee0f6a6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 11 Aug 2005 20:38:33 +0000 Subject: [PATCH] * Some minor error handling cleanups * Please use uint16_t for port numbers. This type is defined in inttypes.h which is available nearly everywhere git-svn-id: file:///home/lennart/svn/public/avahi/trunk@297 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-client/client.c | 18 ++++++++---------- avahi-client/client.h | 4 +++- avahi-client/entrygroup.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/avahi-client/client.c b/avahi-client/client.c index 2ef1bf6..49c82d5 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -197,27 +197,23 @@ avahi_client_new (AvahiClientCallback callback, void *user_data) AvahiClient *tmp = NULL; DBusError error; - tmp = g_new (AvahiClient, 1); + dbus_error_init (&error); - if (tmp == NULL) + if (!(tmp = malloc(sizeof(AvahiClient)))) goto fail; AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, tmp->groups); AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, tmp->domain_browsers); AVAHI_LLIST_HEAD_INIT(AvahiServieTypeBrowser, tmp->service_type_browsers); - - dbus_error_init (&error); - + tmp->bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - dbus_connection_setup_with_g_main (tmp->bus, NULL); - if (dbus_error_is_set (&error)) { fprintf(stderr, "Error getting system d-bus: %s\n", error.message); - dbus_error_free (&error); goto fail; } + dbus_connection_setup_with_g_main (tmp->bus, NULL); dbus_connection_set_exit_on_disconnect (tmp->bus, FALSE); if (!dbus_connection_add_filter (tmp->bus, filter_func, tmp, NULL)) @@ -236,7 +232,6 @@ avahi_client_new (AvahiClientCallback callback, void *user_data) if (dbus_error_is_set (&error)) { fprintf (stderr, "Error adding filter match: %s\n", error.message); - dbus_error_free (&error); goto fail; } @@ -251,7 +246,6 @@ avahi_client_new (AvahiClientCallback callback, void *user_data) if (dbus_error_is_set (&error)) { fprintf (stderr, "Error adding filter match: %s\n", error.message); - dbus_error_free (&error); goto fail; } @@ -265,6 +259,10 @@ avahi_client_new (AvahiClientCallback callback, void *user_data) fail: free (tmp); + + if (dbus_error_is_set(&error)) + dbus_error_free(&error); + return NULL; } diff --git a/avahi-client/client.h b/avahi-client/client.h index 9654206..f3716eb 100644 --- a/avahi-client/client.h +++ b/avahi-client/client.h @@ -22,6 +22,8 @@ USA. ***/ +#include + #include #include #include @@ -104,7 +106,7 @@ avahi_entry_group_add_service (AvahiEntryGroup *group, const char *type, const char *domain, const char *host, - int port, + uint16_t port, AvahiStringList *txt); /** Get the D-Bus path of an AvahiEntryGroup object, for debugging purposes only. */ diff --git a/avahi-client/entrygroup.c b/avahi-client/entrygroup.c index 06f8d9d..ea56ee2 100644 --- a/avahi-client/entrygroup.c +++ b/avahi-client/entrygroup.c @@ -204,7 +204,7 @@ avahi_entry_group_add_service (AvahiEntryGroup *group, const char *type, const char *domain, const char *host, - int port, + uint16_t port, AvahiStringList *txt) { DBusMessage *message; -- 2.39.5