[aravis] interface: coding style fix and memory leak fix.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] interface: coding style fix and memory leak fix.
- Date: Fri, 27 Jan 2012 21:18:54 +0000 (UTC)
commit 1cfc04f0ffb56aad225f31eb5f1f02f1670b3449
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Fri Jan 27 22:17:31 2012 +0100
interface: coding style fix and memory leak fix.
src/arvfakeinterface.c | 12 ++++++++----
src/arvgvinterface.c | 13 +++++++++----
src/arvinterface.c | 24 ++++++++++++++++++------
src/arvinterface.h | 6 ++++++
4 files changed, 41 insertions(+), 14 deletions(-)
---
diff --git a/src/arvfakeinterface.c b/src/arvfakeinterface.c
index 47d7301..c13a209 100644
--- a/src/arvfakeinterface.c
+++ b/src/arvfakeinterface.c
@@ -41,12 +41,16 @@ struct _ArvFakeInterfacePrivate {
static void
arv_fake_interface_update_device_list (ArvInterface *interface, GArray *device_ids)
{
- char **device_id = g_new0 (char*, 2 + 1);
+ ArvInterfaceDeviceIds *ids;
+
+ ids = g_new0 (ArvInterfaceDeviceIds, 1);
g_array_set_size (device_ids, 0);
- device_id[0] = g_strdup (ARV_FAKE_DEVICE_ID);
- device_id[1] = g_strdup (ARV_FAKE_PHYSICAL_ID);
- g_array_append_val (device_ids, device_id);
+
+ ids->device = g_strdup (ARV_FAKE_DEVICE_ID);
+ ids->physical = g_strdup (ARV_FAKE_PHYSICAL_ID);
+
+ g_array_append_val (device_ids, ids);
}
static ArvDevice *
diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c
index 4be7050..e58d6d0 100644
--- a/src/arvgvinterface.c
+++ b/src/arvgvinterface.c
@@ -314,10 +314,15 @@ arv_gv_interface_update_device_list (ArvInterface *interface, GArray *device_ids
g_hash_table_iter_init (&iter, gv_interface->priv->devices);
while (g_hash_table_iter_next (&iter, &key, &value)) {
- char **device_id = g_new0 (char*, 2 + 1);
- device_id[0] = g_strdup (key);
- device_id[1] = g_strdup (((ArvGvInterfaceDeviceInfos *)value)->mac_string);
- g_array_append_val (device_ids, device_id);
+ ArvInterfaceDeviceIds *ids;
+ ArvGvInterfaceDeviceInfos *infos = value;
+
+ ids = g_new0 (ArvInterfaceDeviceIds, 1);
+
+ ids->device = g_strdup (key);
+ ids->physical = g_strdup (infos->mac_string);
+
+ g_array_append_val (device_ids, ids);
}
}
diff --git a/src/arvinterface.c b/src/arvinterface.c
index dd642f3..7e96c59 100644
--- a/src/arvinterface.c
+++ b/src/arvinterface.c
@@ -39,6 +39,18 @@ struct _ArvInterfacePrivate {
GArray *device_ids;
};
+static void
+arv_interface_clear_device_ids (ArvInterface *interface)
+{
+ unsigned int i;
+
+ for (i = 0; i < interface->priv->device_ids->len; i++) {
+ g_free (g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, i)->device);
+ g_free (g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, i)->physical);
+ }
+ g_array_set_size (interface->priv->device_ids, 0);
+}
+
/**
* arv_interface_update_device_list
* @interface: a #ArvInterface
@@ -52,6 +64,8 @@ arv_interface_update_device_list (ArvInterface *interface)
{
g_return_if_fail (ARV_IS_INTERFACE (interface));
+ arv_interface_clear_device_ids (interface);
+
ARV_INTERFACE_GET_CLASS (interface)->update_device_list (interface, interface->priv->device_ids);
}
@@ -93,7 +107,7 @@ arv_interface_get_device_id (ArvInterface *interface, unsigned int index)
if (index >= interface->priv->device_ids->len)
return NULL;
- return g_array_index (interface->priv->device_ids, char **, index)[0];
+ return g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, index)->device;
}
/**
@@ -119,7 +133,7 @@ arv_interface_get_device_physical_id (ArvInterface *interface, unsigned int inde
if (index >= interface->priv->device_ids->len)
return NULL;
- return g_array_index (interface->priv->device_ids, char **, index)[1];
+ return g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, index)->physical;
}
/**
* arv_interface_open_device
@@ -152,19 +166,17 @@ arv_interface_init (ArvInterface *interface)
{
interface->priv = G_TYPE_INSTANCE_GET_PRIVATE (interface, ARV_TYPE_INTERFACE, ArvInterfacePrivate);
- interface->priv->device_ids = g_array_new (FALSE, TRUE, sizeof (char **));
+ interface->priv->device_ids = g_array_new (FALSE, TRUE, sizeof (ArvInterfaceDeviceIds *));
}
static void
arv_interface_finalize (GObject *object)
{
ArvInterface *interface = ARV_INTERFACE (object);
- unsigned int i;
parent_class->finalize (object);
- for (i = 0; i < interface->priv->device_ids->len; i++)
- g_strfreev (g_array_index (interface->priv->device_ids, char **, i));
+ arv_interface_clear_device_ids (interface);
g_array_free (interface->priv->device_ids, TRUE);
interface->priv->device_ids = NULL;
}
diff --git a/src/arvinterface.h b/src/arvinterface.h
index 976d174..f75f7eb 100644
--- a/src/arvinterface.h
+++ b/src/arvinterface.h
@@ -24,9 +24,15 @@
#define ARV_INTERFACE_H
#include <arvtypes.h>
+#include <arvdevice.h>
G_BEGIN_DECLS
+typedef struct {
+ char *device;
+ char *physical;
+} ArvInterfaceDeviceIds;
+
#define ARV_TYPE_INTERFACE (arv_interface_get_type ())
#define ARV_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_INTERFACE, ArvInterface))
#define ARV_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_INTERFACE, ArvInterfaceClass))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]