summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacio Casal Quinteiro <icq@gnome.org>2015-01-08 12:13:46 +0100
committerIgnacio Casal Quinteiro <icq@gnome.org>2015-01-08 12:16:34 +0100
commitdd4c51280e5fbcc56d3d46669377542c6589e87d (patch)
tree084ff2d4c9ff2cda2646da5254c13dfe70f6272a
parentfac8f21e5e111e62571c1e849da6c622c80ffc0a (diff)
downloadgusb-dd4c51280e5fbcc56d3d46669377542c6589e87d.tar.gz
Remove the cleanup attributes from the rest of the code
-rw-r--r--gusb/gusb-context.c48
-rw-r--r--gusb/gusb-device.c8
-rw-r--r--tools/gusb-main.c17
3 files changed, 54 insertions, 19 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c
index 1334b16..7768e18 100644
--- a/gusb/gusb-context.c
+++ b/gusb/gusb-context.c
@@ -30,7 +30,6 @@
#include <libusb-1.0/libusb.h>
-#include "gusb-cleanup.h"
#include "gusb-context.h"
#include "gusb-context-private.h"
#include "gusb-device-private.h"
@@ -725,13 +724,14 @@ g_usb_context_find_by_vid_pid (GUsbContext *context,
return device;
}
static gboolean
-g_usb_context_load_usb_ids (GUsbContext *context, GError **error)
+g_usb_context_load_usb_ids (GUsbContext *context,
+ GError **error)
{
guint16 pid;
guint16 vid = 0x0000;
guint i;
- _cleanup_free_ gchar *data = NULL;
- _cleanup_strv_free_ gchar **lines = NULL;
+ gchar *data = NULL;
+ gchar **lines = NULL;
/* already loaded */
if (g_hash_table_size (context->priv->dict_usb_ids) > 0)
@@ -740,30 +740,41 @@ g_usb_context_load_usb_ids (GUsbContext *context, GError **error)
/* parse */
if (!g_file_get_contents ("/usr/share/hwdata/usb.ids", &data, NULL, error))
return FALSE;
+
lines = g_strsplit (data, "\n", -1);
+ g_free (data);
+
for (i = 0; lines[i] != NULL; i++) {
if (lines[i][0] == '#')
continue;
+
if (lines[i][0] == '\0')
continue;
+
if (lines[i][0] != '\t') {
lines[i][4] = '\0';
+
vid = g_ascii_strtoull (lines[i], NULL, 16);
if (vid == 0)
break;
+
g_hash_table_insert (context->priv->dict_usb_ids,
- g_strdup (lines[i]),
- g_strdup (lines[i] + 6));
+ g_strdup (lines[i]),
+ g_strdup (lines[i] + 6));
} else {
if (vid == 0x0000)
break;
+
lines[i][5] = '\0';
pid = g_ascii_strtoull (lines[i] + 1, NULL, 16);
g_hash_table_insert (context->priv->dict_usb_ids,
- g_strdup_printf ("%04x:%04x", vid, pid),
- g_strdup (lines[i] + 7));
+ g_strdup_printf ("%04x:%04x", vid, pid),
+ g_strdup (lines[i] + 7));
}
}
+
+ g_strfreev (lines);
+
return TRUE;
}
@@ -780,10 +791,12 @@ g_usb_context_load_usb_ids (GUsbContext *context, GError **error)
* Since: 0.1.5
**/
const gchar *
-_g_usb_context_lookup_vendor (GUsbContext *context, guint16 vid, GError **error)
+_g_usb_context_lookup_vendor (GUsbContext *context,
+ guint16 vid,
+ GError **error)
{
const gchar *tmp;
- _cleanup_free_ gchar *key = NULL;
+ gchar *key = NULL;
g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -800,8 +813,12 @@ _g_usb_context_lookup_vendor (GUsbContext *context, guint16 vid, GError **error)
G_USB_CONTEXT_ERROR,
G_USB_CONTEXT_ERROR_INTERNAL,
"failed to find vid %s", key);
+ g_free (key);
return NULL;
}
+
+ g_free (key);
+
return tmp;
}
@@ -819,10 +836,13 @@ _g_usb_context_lookup_vendor (GUsbContext *context, guint16 vid, GError **error)
* Since: 0.1.5
**/
const gchar *
-_g_usb_context_lookup_product (GUsbContext *context, guint16 vid, guint16 pid, GError **error)
+_g_usb_context_lookup_product (GUsbContext *context,
+ guint16 vid,
+ guint16 pid,
+ GError **error)
{
const gchar *tmp;
- _cleanup_free_ gchar *key = NULL;
+ gchar *key = NULL;
g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -839,8 +859,12 @@ _g_usb_context_lookup_product (GUsbContext *context, guint16 vid, guint16 pid, G
G_USB_CONTEXT_ERROR,
G_USB_CONTEXT_ERROR_INTERNAL,
"failed to find vid %s", key);
+ g_free (key);
return NULL;
}
+
+ g_free (key);
+
return tmp;
}
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c
index 5ddf687..49d7e86 100644
--- a/gusb/gusb-device.c
+++ b/gusb/gusb-device.c
@@ -33,7 +33,6 @@
#include <libusb-1.0/libusb.h>
-#include "gusb-cleanup.h"
#include "gusb-context.h"
#include "gusb-context-private.h"
#include "gusb-util.h"
@@ -84,9 +83,11 @@ g_usb_device_get_parent (GUsbDevice *device)
{
GUsbDevicePrivate *priv = device->priv;
libusb_device *parent;
+
parent = libusb_get_parent (priv->device);
if (parent == NULL)
return NULL;
+
return g_usb_context_find_by_bus_address (priv->context,
libusb_get_bus_number (parent),
libusb_get_device_address (parent),
@@ -108,7 +109,7 @@ g_usb_device_get_children (GUsbDevice *device)
GUsbDevice *device_tmp;
GUsbDevicePrivate *priv = device->priv;
guint i;
- _cleanup_ptrarray_unref_ GPtrArray *devices = NULL;
+ GPtrArray *devices = NULL;
/* find any devices that have @device as a parent */
children = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
@@ -118,6 +119,9 @@ g_usb_device_get_children (GUsbDevice *device)
if (priv->device == libusb_get_parent (device_tmp->priv->device))
g_ptr_array_add (children, g_object_ref (device_tmp));
}
+
+ g_ptr_array_unref (devices);
+
return children;
}
diff --git a/tools/gusb-main.c b/tools/gusb-main.c
index bb8c3de..c12b418 100644
--- a/tools/gusb-main.c
+++ b/tools/gusb-main.c
@@ -23,7 +23,6 @@
#include <glib.h>
#include <gusb/gusb.h>
-#include <gusb/gusb-cleanup.h>
#include <string.h>
/**
@@ -206,9 +205,9 @@ moo_cb (GNode *node, gpointer data)
GNode *n;
guint i;
const gchar *tmp;
- _cleanup_free_ gchar *product = NULL;
- _cleanup_free_ gchar *vendor = NULL;
- _cleanup_string_free_ GString *str = NULL;
+ gchar *product = NULL;
+ gchar *vendor = NULL;
+ GString *str = NULL;
if (device == NULL) {
g_print ("Root Device\n");
@@ -267,7 +266,12 @@ moo_cb (GNode *node, gpointer data)
/* add bus:address */
g_string_append_printf (str, "%s - %s", vendor, product);
+ g_free (product);
+ g_free (vendor);
+
g_print ("%s\n", str->str);
+ g_string_free (str, TRUE);
+
return FALSE;
}
@@ -282,7 +286,7 @@ gusb_cmd_show (GUsbCmdPrivate *priv, gchar **values, GError **error)
guint i;
GUsbDevice *device;
GUsbDevice *parent;
- _cleanup_ptrarray_unref_ GPtrArray *devices = NULL;
+ GPtrArray *devices = NULL;
/* sort */
devices = g_usb_context_get_devices (priv->usb_ctx);
@@ -308,7 +312,10 @@ gusb_cmd_show (GUsbCmdPrivate *priv, gchar **values, GError **error)
g_node_append_data (n, device);
}
+
+ g_ptr_array_unref (devices);
g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, moo_cb, priv);
+
return TRUE;
}