Index: ChangeLog =================================================================== RCS file: /cvs/hal/hal/ChangeLog,v retrieving revision 1.936 diff -u -3 -p -u -r1.936 ChangeLog --- ChangeLog 14 Jul 2006 17:46:57 -0000 1.936 +++ ChangeLog 17 Jul 2006 14:48:39 -0000 @@ -1,3 +1,24 @@ +2006-07-17 Danny Kukawka + + Close memory leaks from not freed DBusError objects: + + * libhal-storage/libhal-storage.c: (libhal_drive_from_udi), + (libhal_volume_from_udi), (libhal_drive_from_device_file), + (libhal_volume_from_device_file), (libhal_drive_find_all_volumes), + (libhal_drive_policy_default_get_mount_root), + (libhal_drive_policy_default_use_managed_keyword), + (libhal_drive_policy_default_get_managed_keyword_primary), + (libhal_drive_policy_default_get_managed_keyword_secondary), + (mopts_collect): free DBusError + + * libhal/libhal.c: (filter_func): free DBusError, (libhal_new_device): + removed not needed return, (libhal_ctx_shutdown): added + dbus_move_error to display the correct error message and tp return the + related DBusError + + * libhal/libhal.h: Added macro LIBHAL_FREE_DBUS_ERROR to check and + free DBusError. + 2006-07-14 Kay Sievers * tools/hal-device.c: (main): Index: libhal/libhal.c =================================================================== RCS file: /cvs/hal/hal/libhal/libhal.c,v retrieving revision 1.60 diff -u -3 -p -u -r1.60 libhal.c --- libhal/libhal.c 3 Jul 2006 16:42:01 -0000 1.60 +++ libhal/libhal.c 17 Jul 2006 14:48:39 -0000 @@ -810,6 +810,7 @@ filter_func (DBusConnection * connection return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } + LIBHAL_FREE_DBUS_ERROR(&error); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -2001,8 +2002,6 @@ libhal_new_device (LibHalContext *ctx, D if (value == NULL) { fprintf (stderr, "%s %d : error allocating memory\n", __FILE__, __LINE__); - /** @todo FIXME cleanup */ - return NULL; } dbus_message_unref (message); @@ -3020,6 +3019,7 @@ libhal_ctx_shutdown (LibHalContext *ctx, "sender='org.freedesktop.Hal'," "path='/org/freedesktop/Hal/Manager'", &myerror); if (dbus_error_is_set (&myerror)) { + dbus_move_error (&myerror, error); fprintf (stderr, "%s %d : Error unsubscribing to signals, error=%s\n", __FILE__, __LINE__, error->message); /** @todo clean up */ Index: libhal/libhal.h =================================================================== RCS file: /cvs/hal/hal/libhal/libhal.h,v retrieving revision 1.35 diff -u -3 -p -u -r1.35 libhal.h --- libhal/libhal.h 9 Jun 2006 02:19:32 -0000 1.35 +++ libhal/libhal.h 17 Jul 2006 14:48:39 -0000 @@ -35,6 +35,13 @@ extern "C" { #endif #endif +#define LIBHAL_FREE_DBUS_ERROR(_dbus_error_) \ + do { \ + if (dbus_error_is_set(_dbus_error_)) \ + dbus_error_free (_dbus_error_); \ + } while (0) + + /** * LIBHAL_CHECK_LIBHALCONTEXT: * @_ctx_: the context Index: libhal-storage/libhal-storage.c =================================================================== RCS file: /cvs/hal/hal/libhal-storage/libhal-storage.c,v retrieving revision 1.38 diff -u -3 -p -u -r1.38 libhal-storage.c --- libhal-storage/libhal-storage.c 10 Jul 2006 23:30:28 -0000 1.38 +++ libhal-storage/libhal-storage.c 17 Jul 2006 14:48:39 -0000 @@ -1027,6 +1027,7 @@ libhal_drive_from_udi (LibHalContext *ha return drive; error: + LIBHAL_FREE_DBUS_ERROR(&error); libhal_free_string (bus_textual); libhal_free_property_set (properties); libhal_drive_free (drive); @@ -1196,6 +1197,7 @@ libhal_volume_from_udi (LibHalContext *h libhal_free_property_set (properties); return vol; error: + LIBHAL_FREE_DBUS_ERROR(&error); libhal_free_string (vol_fsusage_textual); libhal_free_string (disc_type_textual); libhal_free_property_set (properties); @@ -1267,6 +1269,8 @@ libhal_drive_from_device_file (LibHalCon } else if (libhal_device_query_capability (hal_ctx, udi, "storage", &err2)) { found_udi = strdup (udi); } + LIBHAL_FREE_DBUS_ERROR(&err1); + LIBHAL_FREE_DBUS_ERROR(&err2); } libhal_free_string_array (hal_udis); @@ -1276,6 +1280,7 @@ libhal_drive_from_device_file (LibHalCon free (found_udi); out: + LIBHAL_FREE_DBUS_ERROR(&error); return result; } @@ -1322,6 +1327,7 @@ libhal_volume_from_device_file (LibHalCo free (found_udi); out: + LIBHAL_FREE_DBUS_ERROR(&error); return result; } @@ -1598,6 +1604,7 @@ libhal_drive_find_all_volumes (LibHalCon result[*num_volumes] = NULL; out: + LIBHAL_FREE_DBUS_ERROR(&error); libhal_free_string_array (udis); return result; } @@ -1643,49 +1650,65 @@ libhal_volume_crypto_get_clear_volume_ud char * libhal_drive_policy_default_get_mount_root (LibHalContext *hal_ctx) { + char *result; DBusError error; LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL); dbus_error_init (&error); - return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer", - "storage.policy.default.mount_root", &error); + result = libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer", + "storage.policy.default.mount_root", &error); + LIBHAL_FREE_DBUS_ERROR(&error); + + return result; } dbus_bool_t libhal_drive_policy_default_use_managed_keyword (LibHalContext *hal_ctx) { + dbus_bool_t result; DBusError error; LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, FALSE); dbus_error_init (&error); - return libhal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer", - "storage.policy.default.use_managed_keyword", &error); + result = libhal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer", + "storage.policy.default.use_managed_keyword", &error); + LIBHAL_FREE_DBUS_ERROR(&error); + + return result; } char * libhal_drive_policy_default_get_managed_keyword_primary (LibHalContext *hal_ctx) { + char *result; DBusError error; LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL); dbus_error_init (&error); - return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer", - "storage.policy.default.managed_keyword.primary", &error); + result = libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer", + "storage.policy.default.managed_keyword.primary", &error); + LIBHAL_FREE_DBUS_ERROR(&error); + + return result; } char * libhal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx) { + char *result; DBusError error; LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL); dbus_error_init (&error); - return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer", - "storage.policy.default.managed_keyword.secondary", &error); + result = libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer", + "storage.policy.default.managed_keyword.secondary", &error); + LIBHAL_FREE_DBUS_ERROR(&error); + + return result; } /*************************************************************************/ @@ -1730,6 +1753,7 @@ mopts_collect (LibHalContext *hal_ctx, c properties = libhal_device_get_all_properties (hal_ctx, udi, &error); if (properties == NULL) goto error; + for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) { int type; char *key; @@ -1784,6 +1808,7 @@ mopts_collect (LibHalContext *hal_ctx, c } } error: + LIBHAL_FREE_DBUS_ERROR(&error); libhal_free_property_set (properties); }