diff options
author | Danny Kukawka <danny.kukawka@web.de> | 2006-07-29 22:51:34 +0200 |
---|---|---|
committer | Danny Kukawka <danny.kukawka@web.de> | 2006-07-29 22:51:34 +0200 |
commit | 43b54e7f372d1b4b4019dc6ccdae578600b92d01 (patch) | |
tree | 207794edd1280c3c64ba347c8352d52a08758e30 /tools | |
parent | 701a95e0bb1969607a9628d5a5ccf364cad5a2b5 (diff) |
Close memory leaks from not freed DBusError in tools src dir
Closed several memoryleaks related to not freed DBusError objects
in *.c files in the tools dir by using LIBHAL_FREE_DBUS_ERROR macro.
This include also a cleanup in hal-storage-mount.c and a fix for lshal
to avoid start monitoring device list if we can't set the watch to
all device properties.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/hal-device.c | 13 | ||||
-rw-r--r-- | tools/hal-storage-eject.c | 2 | ||||
-rw-r--r-- | tools/hal-storage-mount.c | 18 | ||||
-rw-r--r-- | tools/hal-storage-shared.c | 1 | ||||
-rw-r--r-- | tools/hal-storage-unmount.c | 2 | ||||
-rw-r--r-- | tools/hal_find_by_capability.c | 4 | ||||
-rw-r--r-- | tools/hal_find_by_property.c | 3 | ||||
-rw-r--r-- | tools/hal_get_property.c | 18 | ||||
-rw-r--r-- | tools/hal_set_property.c | 4 | ||||
-rw-r--r-- | tools/lshal.c | 26 |
10 files changed, 71 insertions, 20 deletions
diff --git a/tools/hal-device.c b/tools/hal-device.c index a5b7c83f..c421b15a 100644 --- a/tools/hal-device.c +++ b/tools/hal-device.c @@ -132,6 +132,7 @@ int main(int argc, char **argv) if (!(conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { fprintf(stderr, "error: dbus_bus_get: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 2; } @@ -140,6 +141,7 @@ int main(int argc, char **argv) if (!libhal_ctx_set_dbus_connection(hal_ctx, conn)) return 4; if (!libhal_ctx_init(hal_ctx, &error)) { fprintf(stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 5; } @@ -201,6 +203,7 @@ int dump_devices(LibHalContext *hal_ctx, char *arg) if (!udi) { if (!(device_names = libhal_get_all_devices(hal_ctx, &num_devices, &error))) { fprintf(stderr, "Empty HAL device list.\n"); + LIBHAL_FREE_DBUS_ERROR (&error); return 31; } } else { @@ -307,6 +310,7 @@ int remove_udi(LibHalContext *hal_ctx, char *arg) if (opt.remove) { if (!libhal_remove_device(hal_ctx, udi, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 12; } @@ -350,6 +354,7 @@ int add_udi(LibHalContext *hal_ctx, char *arg) if (!new_dev.real_udi) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); free(new_dev.real_udi); return 22; @@ -371,6 +376,7 @@ int add_udi(LibHalContext *hal_ctx, char *arg) if (!dev_exists) { if (!libhal_device_commit_to_gdl(hal_ctx, new_dev.real_udi, new_dev.udi, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); free(new_dev.real_udi); err = err ?: 23; @@ -538,6 +544,7 @@ int add_properties(LibHalContext *hal_ctx, new_dev_t *nd, lh_prop_t *prop) ( p->type != old_type || p->type == LIBHAL_PROPERTY_TYPE_STRLIST)) { if (!libhal_device_remove_property(hal_ctx, nd->real_udi, p->key, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 41; } } @@ -548,24 +555,28 @@ int add_properties(LibHalContext *hal_ctx, new_dev_t *nd, lh_prop_t *prop) case LIBHAL_PROPERTY_TYPE_BOOLEAN: if (!libhal_device_set_property_bool(hal_ctx, nd->real_udi, p->key, p->bool_value, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 42; } break; case LIBHAL_PROPERTY_TYPE_INT32: if (!libhal_device_set_property_int(hal_ctx, nd->real_udi, p->key, p->int_value, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 42; } break; case LIBHAL_PROPERTY_TYPE_UINT64: if (!libhal_device_set_property_uint64(hal_ctx, nd->real_udi, p->key, p->uint64_value, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 42; } break; case LIBHAL_PROPERTY_TYPE_DOUBLE: if (!libhal_device_set_property_double(hal_ctx, nd->real_udi, p->key, p->double_value, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 42; } break; @@ -573,6 +584,7 @@ int add_properties(LibHalContext *hal_ctx, new_dev_t *nd, lh_prop_t *prop) if (!strcmp(p->key, "info.udi")) udi3 = p->str_value; if (!libhal_device_set_property_string(hal_ctx, nd->real_udi, p->key, p->str_value, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 42; } break; @@ -580,6 +592,7 @@ int add_properties(LibHalContext *hal_ctx, new_dev_t *nd, lh_prop_t *prop) for(s = p->strlist_value; *s; s++) { if (!libhal_device_property_strlist_append(hal_ctx, nd->real_udi, p->key, *s, &error)) { fprintf(stderr, "%s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 42; } } diff --git a/tools/hal-storage-eject.c b/tools/hal-storage-eject.c index e7163d6b..b347ad9c 100644 --- a/tools/hal-storage-eject.c +++ b/tools/hal-storage-eject.c @@ -159,6 +159,7 @@ main (int argc, char *argv[]) dbus_error_init (&error); if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) { printf ("Cannot connect to hald\n"); + LIBHAL_FREE_DBUS_ERROR (&error); usage (); } @@ -166,6 +167,7 @@ main (int argc, char *argv[]) system_bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); if (system_bus == NULL) { printf ("Cannot connect to the system bus\n"); + LIBHAL_FREE_DBUS_ERROR (&error); usage (); } pol_ctx = libpolkit_new_context (system_bus); diff --git a/tools/hal-storage-mount.c b/tools/hal-storage-mount.c index 2dfcb3d2..d24d748a 100644 --- a/tools/hal-storage-mount.c +++ b/tools/hal-storage-mount.c @@ -251,9 +251,10 @@ volume_findby (LibHalContext *hal_ctx, const char *property, const char *value) dbus_error_init (&error); if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, property, - value, &num_hal_udis, &error)) == NULL) + value, &num_hal_udis, &error)) == NULL) { + LIBHAL_FREE_DBUS_ERROR (&error); goto out; - + } for (i = 0; i < num_hal_udis; i++) { char *udi; udi = hal_udis[i]; @@ -456,22 +457,18 @@ handle_mount (LibHalContext *hal_ctx, LibPolKitContext *pol_ctx, const char *udi if (libhal_volume_is_mounted (volume)) { already_mounted (device); } - } else { - bailout_if_mounted (device); - } - - if (volume != NULL) { + dbus_error_init (&error); if (libhal_device_get_property_bool (hal_ctx, udi, "volume.ignore", &error) || dbus_error_is_set (&error)) { + LIBHAL_FREE_DBUS_ERROR (&error); permission_denied_volume_ignore (device); } - } - if (volume != NULL) { label = libhal_volume_get_label (volume); uuid = libhal_volume_get_uuid (volume); } else { + bailout_if_mounted (device); label = NULL; uuid = NULL; } @@ -589,6 +586,7 @@ handle_mount (LibHalContext *hal_ctx, LibPolKitContext *pol_ctx, const char *udi allowed_options = libhal_device_get_property_strlist (hal_ctx, udi, "volume.mount.valid_options", &error); if (dbus_error_is_set (&error)) { unknown_error ("Cannot get volume.mount.valid_options"); + dbus_error_free (&error); } #ifdef DEBUG @@ -928,6 +926,7 @@ main (int argc, char *argv[]) dbus_error_init (&error); if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) { printf ("Cannot connect to hald\n"); + LIBHAL_FREE_DBUS_ERROR (&error); usage (); } @@ -935,6 +934,7 @@ main (int argc, char *argv[]) system_bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); if (system_bus == NULL) { printf ("Cannot connect to the system bus\n"); + LIBHAL_FREE_DBUS_ERROR (&error); usage (); } pol_ctx = libpolkit_new_context (system_bus); diff --git a/tools/hal-storage-shared.c b/tools/hal-storage-shared.c index c49c1069..0a4f4899 100644 --- a/tools/hal-storage-shared.c +++ b/tools/hal-storage-shared.c @@ -249,6 +249,7 @@ handle_unmount (LibHalContext *hal_ctx, LibPolKitContext *pol_ctx, const char *u dbus_error_init (&error); if (libhal_device_get_property_bool (hal_ctx, udi, "volume.ignore", &error) || dbus_error_is_set (&error)) { + LIBHAL_FREE_DBUS_ERROR (&error); permission_denied_volume_ignore (device); } diff --git a/tools/hal-storage-unmount.c b/tools/hal-storage-unmount.c index 5af680ad..99a3fb49 100644 --- a/tools/hal-storage-unmount.c +++ b/tools/hal-storage-unmount.c @@ -104,6 +104,7 @@ main (int argc, char *argv[]) dbus_error_init (&error); if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) { printf ("Cannot connect to hald\n"); + LIBHAL_FREE_DBUS_ERROR (&error); usage (); } @@ -111,6 +112,7 @@ main (int argc, char *argv[]) system_bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); if (system_bus == NULL) { printf ("Cannot connect to the system bus\n"); + LIBHAL_FREE_DBUS_ERROR (&error); usage (); } pol_ctx = libpolkit_new_context (system_bus); diff --git a/tools/hal_find_by_capability.c b/tools/hal_find_by_capability.c index 27d70f88..a4b95ef1 100644 --- a/tools/hal_find_by_capability.c +++ b/tools/hal_find_by_capability.c @@ -138,14 +138,17 @@ main (int argc, char *argv[]) dbus_error_init (&error); if ((hal_ctx = libhal_ctx_new ()) == NULL) { fprintf (stderr, "error: libhal_ctx_new\n"); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) { fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } if (!libhal_ctx_init (hal_ctx, &error)) { fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } @@ -154,6 +157,7 @@ main (int argc, char *argv[]) if (dbus_error_is_set (&error)) { fprintf (stderr, "error: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } diff --git a/tools/hal_find_by_property.c b/tools/hal_find_by_property.c index fa4899f4..8c25710d 100644 --- a/tools/hal_find_by_property.c +++ b/tools/hal_find_by_property.c @@ -150,10 +150,12 @@ main (int argc, char *argv[]) } if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) { fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } if (!libhal_ctx_init (hal_ctx, &error)) { fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } @@ -162,6 +164,7 @@ main (int argc, char *argv[]) if (dbus_error_is_set (&error)) { fprintf (stderr, "error: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } diff --git a/tools/hal_get_property.c b/tools/hal_get_property.c index 1f624847..b1c5db08 100644 --- a/tools/hal_get_property.c +++ b/tools/hal_get_property.c @@ -159,16 +159,19 @@ main (int argc, char *argv[]) } if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) { fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } if (!libhal_ctx_init (hal_ctx, &error)) { fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } type = libhal_device_get_property_type (hal_ctx, udi, key, &error); if (type == LIBHAL_PROPERTY_TYPE_INVALID) { fprintf (stderr, "error: libhal_device_get_property_type: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } /* emit the value to stdout */ @@ -212,12 +215,14 @@ main (int argc, char *argv[]) unsigned int i; char **strlist; - strlist = libhal_device_get_property_strlist (hal_ctx, udi, key, &error); - for (i = 0; strlist[i] != 0; i++) { - printf ("%s", strlist[i]); - if (strlist[i+1] != NULL) - printf (" "); - } + if ((strlist = libhal_device_get_property_strlist (hal_ctx, udi, key, &error)) != NULL) { + + for (i = 0; strlist[i] != 0; i++) { + printf ("%s", strlist[i]); + if (strlist[i+1] != NULL) + printf (" "); + } + } break; } default: @@ -228,6 +233,7 @@ main (int argc, char *argv[]) if (dbus_error_is_set (&error)) { fprintf (stderr, "error: %s: %s\n", error.name, error.message); + dbus_error_free (&error); return 1; } diff --git a/tools/hal_set_property.c b/tools/hal_set_property.c index d1019788..7bb6094d 100644 --- a/tools/hal_set_property.c +++ b/tools/hal_set_property.c @@ -226,10 +226,12 @@ main (int argc, char *argv[]) } if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) { fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } if (!libhal_ctx_init (hal_ctx, &error)) { fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } @@ -237,6 +239,7 @@ main (int argc, char *argv[]) rc = libhal_device_remove_property (hal_ctx, udi, key, &error); if (!rc) { fprintf (stderr, "error: libhal_device_remove_property: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } } else { @@ -268,6 +271,7 @@ main (int argc, char *argv[]) } if (!rc) { fprintf (stderr, "error: libhal_device_set_property: %s: %s\n", error.name, error.message); + dbus_error_free (&error); return 1; } } diff --git a/tools/lshal.c b/tools/lshal.c index 42e99078..5e103f85 100644 --- a/tools/lshal.c +++ b/tools/lshal.c @@ -103,8 +103,10 @@ print_props (const char *udi) * essence an IPC call and other stuff may * be happening.. */ - if (props == NULL) + if (props == NULL) { + LIBHAL_FREE_DBUS_ERROR (&error); return; + } for (libhal_psi_init (&it, props); libhal_psi_has_more (&it); libhal_psi_next (&it)) { type = libhal_psi_get_type (&it); @@ -180,8 +182,10 @@ dump_device (const char *udi) dbus_error_init (&error); - if (!libhal_device_exists (hal_ctx, udi, &error)) + if (!libhal_device_exists (hal_ctx, udi, &error)) { + LIBHAL_FREE_DBUS_ERROR (&error); return; + } if (long_list) { printf ("udi = '%s'\n", udi); @@ -253,8 +257,10 @@ dump_devices (void) dbus_error_init (&error); device_names = libhal_get_all_devices (hal_ctx, &num_devices, &error); - if (device_names == NULL) + if (device_names == NULL) { + LIBHAL_FREE_DBUS_ERROR (&error); DIE (("Couldn't obtain list of devices\n")); + } devices = malloc (sizeof(struct Device) * num_devices); if (!devices) { @@ -454,6 +460,8 @@ print_property (const char *udi, const char *key) fprintf (stderr, "Unknown type %d='%c'\n", type, type); break; } + + LIBHAL_FREE_DBUS_ERROR (&error); } /** Invoked when a property of a device in the Global Device List is @@ -656,6 +664,7 @@ main (int argc, char *argv[]) if (conn == NULL) { fprintf (stderr, "error: dbus_bus_get: %s: %s\n", error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } @@ -676,6 +685,7 @@ main (int argc, char *argv[]) error.name, error.message); fprintf (stderr, "Could not initialise connection to hald. \n " "Normally this mean the HAL daemon (hald) is not running or not ready.\n"); + LIBHAL_FREE_DBUS_ERROR (&error); return 1; } @@ -696,13 +706,19 @@ main (int argc, char *argv[]) if( long_list || short_list || tree_view ) dump_devices (); + if ( libhal_device_property_watch_all (hal_ctx, &error) == FALSE) { + fprintf (stderr, "error: monitoring devicelist - libhal_device_property_watch_all: %s: %s\n", + error.name, error.message); + LIBHAL_FREE_DBUS_ERROR (&error); + return 1; + } printf ("\nStart monitoring devicelist:\n" "-------------------------------------------------\n"); - libhal_device_property_watch_all (hal_ctx, &error); g_main_loop_run (loop); } - libhal_ctx_shutdown (hal_ctx, &error); + if ( libhal_ctx_shutdown (hal_ctx, &error) == FALSE) + LIBHAL_FREE_DBUS_ERROR (&error); libhal_ctx_free (hal_ctx); dbus_connection_close (conn); |