hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Sat Jul 29 13:16:57 PDT 2006
libhal-storage/libhal-storage.c | 54 ++++++++++++++++++++++++++++++----------
libhal/libhal.c | 11 ++++++--
libhal/libhal.h | 12 ++++++++
3 files changed, 62 insertions(+), 15 deletions(-)
New commits:
diff-tree 701a95e0bb1969607a9628d5a5ccf364cad5a2b5 (from 15376ac7c17fa31033adefcfe106935e09b5b0df)
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Sat Jul 29 22:13:37 2006 +0200
Close memory leaks from not freed DBusError in libhal and libhal-storage
Added a macro to libhal to free a DBusError (including a check if the error
was really set and a debug message if this is not the case) and closed several
memory leaks in the libhal and libhal-storage library.
Did some little cleanups in the libraries and fixed wrong displayed/returned
DBusError in libhal_ctx_shutdown().
diff --git a/libhal-storage/libhal-storage.c b/libhal-storage/libhal-storage.c
index 58e9efe..6ce649d 100644
--- a/libhal-storage/libhal-storage.c
+++ b/libhal-storage/libhal-storage.c
@@ -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);
@@ -1244,8 +1246,10 @@ libhal_drive_from_device_file (LibHalCon
dbus_error_init (&error);
if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, "block.device",
- device_file, &num_hal_udis, &error)) == NULL)
+ device_file, &num_hal_udis, &error)) == NULL) {
+ LIBHAL_FREE_DBUS_ERROR(&error);
goto out;
+ }
for (i = 0; i < num_hal_udis; i++) {
char *udi;
@@ -1267,6 +1271,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);
@@ -1322,6 +1328,7 @@ libhal_volume_from_device_file (LibHalCo
free (found_udi);
out:
+ LIBHAL_FREE_DBUS_ERROR(&error);
return result;
}
@@ -1580,8 +1587,10 @@ libhal_drive_find_all_volumes (LibHalCon
/* get initial list... */
dbus_error_init (&error);
if ((udis = libhal_manager_find_device_string_match (hal_ctx, "block.storage_device",
- drive_udi, &num_udis, &error)) == NULL)
+ drive_udi, &num_udis, &error)) == NULL) {
+ LIBHAL_FREE_DBUS_ERROR(&error);
goto out;
+ }
result = malloc (sizeof (char *) * num_udis);
if (result == NULL)
@@ -1643,49 +1652,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);
+ if ((result = libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+ "storage.policy.default.mount_root", &error)) == NULL)
+ 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);
+ if ((result = libhal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+ "storage.policy.default.use_managed_keyword", &error)) == FALSE)
+ 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);
+ if ((result = libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+ "storage.policy.default.managed_keyword.primary", &error)) == NULL)
+ 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);
+ if ((result = libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+ "storage.policy.default.managed_keyword.secondary", &error)) == NULL)
+ LIBHAL_FREE_DBUS_ERROR(&error);
+
+ return result;
}
/*************************************************************************/
@@ -1728,8 +1753,11 @@ mopts_collect (LibHalContext *hal_ctx, c
/* first collect from root computer device */
properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
- if (properties == NULL)
- goto error;
+ if (properties == NULL ) {
+ LIBHAL_FREE_DBUS_ERROR(&error);
+ return;
+ }
+
for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
int type;
char *key;
@@ -1783,7 +1811,7 @@ mopts_collect (LibHalContext *hal_ctx, c
}
}
}
-error:
+
libhal_free_property_set (properties);
}
diff --git a/libhal/libhal.c b/libhal/libhal.c
index 79139d7..2bd203b 100644
--- a/libhal/libhal.c
+++ b/libhal/libhal.c
@@ -735,6 +735,8 @@ filter_func (DBusConnection * connection
if (ctx->device_added != NULL) {
ctx->device_added (ctx, udi);
}
+ } else {
+ LIBHAL_FREE_DBUS_ERROR(&error);
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Manager", "DeviceRemoved")) {
@@ -745,6 +747,8 @@ filter_func (DBusConnection * connection
if (ctx->device_removed != NULL) {
ctx->device_removed (ctx, udi);
}
+ } else {
+ LIBHAL_FREE_DBUS_ERROR(&error);
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Manager","NewCapability")) {
@@ -757,6 +761,8 @@ filter_func (DBusConnection * connection
if (ctx->device_new_capability != NULL) {
ctx->device_new_capability (ctx, udi, capability);
}
+ } else {
+ LIBHAL_FREE_DBUS_ERROR(&error);
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Device", "Condition")) {
@@ -769,6 +775,8 @@ filter_func (DBusConnection * connection
if (ctx->device_condition != NULL) {
ctx->device_condition (ctx, object_path, condition_name, condition_detail);
}
+ } else {
+ LIBHAL_FREE_DBUS_ERROR(&error);
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Device", "PropertyModified")) {
@@ -2001,8 +2009,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 +3026,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 */
diff --git a/libhal/libhal.h b/libhal/libhal.h
index 7e227ab..11af1d2 100644
--- a/libhal/libhal.h
+++ b/libhal/libhal.h
@@ -35,6 +35,18 @@ extern "C" {
#endif
#endif
+#define LIBHAL_FREE_DBUS_ERROR(_dbus_error_) \
+ do { \
+ if (dbus_error_is_set(_dbus_error_)) \
+ dbus_error_free (_dbus_error_); \
+ else \
+ fprintf (stderr, \
+ "%s %d : INFO: called LIBHAL_FREE_DBUS_ERROR " \
+ "but dbusError was not set.\n", \
+ __FILE__, __LINE__); \
+ } while (0)
+
+
/**
* LIBHAL_CHECK_LIBHALCONTEXT:
* @_ctx_: the context
More information about the hal-commit
mailing list